0s autopkgtest [09:34:57]: starting date and time: 2024-12-03 09:34:57+0000 0s autopkgtest [09:34:57]: git checkout: be626eda Fix armhf LXD image generation for plucky 0s autopkgtest [09:34:57]: host juju-7f2275-prod-proposed-migration-environment-9; command line: /home/ubuntu/autopkgtest/runner/autopkgtest --output-dir /tmp/autopkgtest-work.85vdjk9x/out --timeout-copy=6000 --setup-commands 'ln -s /dev/null /etc/systemd/system/bluetooth.service; printf "http_proxy=http://squid.internal:3128\nhttps_proxy=http://squid.internal:3128\nno_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\n" >> /etc/environment' --apt-pocket=proposed=src:tiktoken,src:python3-defaults --apt-upgrade tiktoken --timeout-short=300 --timeout-copy=20000 --timeout-build=20000 '--env=ADT_TEST_TRIGGERS=tiktoken/0.8.0-1build1 python3-defaults/3.12.7-1' -- lxd -r lxd-armhf-10.145.243.27 lxd-armhf-10.145.243.27:autopkgtest/ubuntu/plucky/armhf 64s autopkgtest [09:36:01]: testbed dpkg architecture: armhf 70s autopkgtest [09:36:07]: testbed apt version: 2.9.14ubuntu1 79s autopkgtest [09:36:16]: @@@@@@@@@@@@@@@@@@@@ test bed setup 82s autopkgtest [09:36:19]: testbed release detected to be: None 99s autopkgtest [09:36:36]: updating testbed package index (apt update) 102s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed InRelease [73.9 kB] 102s Get:2 http://ftpmaster.internal/ubuntu plucky InRelease [213 kB] 102s Hit:3 http://ftpmaster.internal/ubuntu plucky-updates InRelease 102s Hit:4 http://ftpmaster.internal/ubuntu plucky-security InRelease 103s Get:5 http://ftpmaster.internal/ubuntu plucky-proposed/universe Sources [781 kB] 103s Get:6 http://ftpmaster.internal/ubuntu plucky-proposed/restricted Sources [9708 B] 103s Get:7 http://ftpmaster.internal/ubuntu plucky-proposed/main Sources [65.3 kB] 103s Get:8 http://ftpmaster.internal/ubuntu plucky-proposed/multiverse Sources [15.1 kB] 103s Get:9 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf Packages [119 kB] 103s Get:10 http://ftpmaster.internal/ubuntu plucky-proposed/restricted armhf Packages [928 B] 103s Get:11 http://ftpmaster.internal/ubuntu plucky-proposed/universe armhf Packages [622 kB] 103s Get:12 http://ftpmaster.internal/ubuntu plucky-proposed/multiverse armhf Packages [7468 B] 103s Get:13 http://ftpmaster.internal/ubuntu plucky/main Sources [1381 kB] 103s Get:14 http://ftpmaster.internal/ubuntu plucky/universe Sources [20.7 MB] 105s Get:15 http://ftpmaster.internal/ubuntu plucky/multiverse Sources [298 kB] 105s Get:16 http://ftpmaster.internal/ubuntu plucky/main armhf Packages [1353 kB] 105s Get:17 http://ftpmaster.internal/ubuntu plucky/universe armhf Packages [14.9 MB] 106s Get:18 http://ftpmaster.internal/ubuntu plucky/multiverse armhf Packages [174 kB] 109s Fetched 40.7 MB in 7s (5649 kB/s) 111s Reading package lists... 120s autopkgtest [09:36:57]: upgrading testbed (apt dist-upgrade and autopurge) 123s Reading package lists... 123s Building dependency tree... 123s Reading state information... 124s Calculating upgrade...Starting pkgProblemResolver with broken count: 0 124s Starting 2 pkgProblemResolver with broken count: 0 124s Done 125s Entering ResolveByKeep 126s 127s The following packages will be upgraded: 127s fwupd gcc-14-base libatomic1 libfwupd3 libgcc-s1 libpython3-stdlib 127s libstdc++6 python3 python3-minimal python3-software-properties 127s software-properties-common 127s 11 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 127s Need to get 6065 kB of archives. 127s After this operation, 1024 B of additional disk space will be used. 127s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf python3-minimal armhf 3.12.7-1 [27.4 kB] 127s Get:2 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf python3 armhf 3.12.7-1 [24.0 kB] 127s Get:3 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf libpython3-stdlib armhf 3.12.7-1 [10.0 kB] 127s Get:4 http://ftpmaster.internal/ubuntu plucky/main armhf libatomic1 armhf 14.2.0-9ubuntu1 [7856 B] 127s Get:5 http://ftpmaster.internal/ubuntu plucky/main armhf gcc-14-base armhf 14.2.0-9ubuntu1 [51.9 kB] 127s Get:6 http://ftpmaster.internal/ubuntu plucky/main armhf libstdc++6 armhf 14.2.0-9ubuntu1 [713 kB] 127s Get:7 http://ftpmaster.internal/ubuntu plucky/main armhf libgcc-s1 armhf 14.2.0-9ubuntu1 [40.9 kB] 127s Get:8 http://ftpmaster.internal/ubuntu plucky/main armhf fwupd armhf 2.0.2-2 [5020 kB] 128s Get:9 http://ftpmaster.internal/ubuntu plucky/main armhf libfwupd3 armhf 2.0.2-2 [124 kB] 128s Get:10 http://ftpmaster.internal/ubuntu plucky/main armhf software-properties-common all 0.107 [16.5 kB] 128s Get:11 http://ftpmaster.internal/ubuntu plucky/main armhf python3-software-properties all 0.107 [30.4 kB] 128s Fetched 6065 kB in 1s (7049 kB/s) 128s (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 ... 59970 files and directories currently installed.) 128s Preparing to unpack .../python3-minimal_3.12.7-1_armhf.deb ... 128s Unpacking python3-minimal (3.12.7-1) over (3.12.6-0ubuntu1) ... 128s Setting up python3-minimal (3.12.7-1) ... 129s (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 ... 59970 files and directories currently installed.) 129s Preparing to unpack .../python3_3.12.7-1_armhf.deb ... 129s Unpacking python3 (3.12.7-1) over (3.12.6-0ubuntu1) ... 129s Preparing to unpack .../libpython3-stdlib_3.12.7-1_armhf.deb ... 129s Unpacking libpython3-stdlib:armhf (3.12.7-1) over (3.12.6-0ubuntu1) ... 129s Preparing to unpack .../libatomic1_14.2.0-9ubuntu1_armhf.deb ... 129s Unpacking libatomic1:armhf (14.2.0-9ubuntu1) over (14.2.0-8ubuntu1) ... 129s Preparing to unpack .../gcc-14-base_14.2.0-9ubuntu1_armhf.deb ... 129s Unpacking gcc-14-base:armhf (14.2.0-9ubuntu1) over (14.2.0-8ubuntu1) ... 129s Setting up gcc-14-base:armhf (14.2.0-9ubuntu1) ... 129s (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 ... 59970 files and directories currently installed.) 129s Preparing to unpack .../libstdc++6_14.2.0-9ubuntu1_armhf.deb ... 129s Unpacking libstdc++6:armhf (14.2.0-9ubuntu1) over (14.2.0-8ubuntu1) ... 129s Setting up libstdc++6:armhf (14.2.0-9ubuntu1) ... 129s (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 ... 59970 files and directories currently installed.) 129s Preparing to unpack .../libgcc-s1_14.2.0-9ubuntu1_armhf.deb ... 129s Unpacking libgcc-s1:armhf (14.2.0-9ubuntu1) over (14.2.0-8ubuntu1) ... 129s Setting up libgcc-s1:armhf (14.2.0-9ubuntu1) ... 129s (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 ... 59970 files and directories currently installed.) 129s Preparing to unpack .../fwupd_2.0.2-2_armhf.deb ... 130s Unpacking fwupd (2.0.2-2) over (2.0.2-1) ... 130s Preparing to unpack .../libfwupd3_2.0.2-2_armhf.deb ... 130s Unpacking libfwupd3:armhf (2.0.2-2) over (2.0.2-1) ... 130s Preparing to unpack .../software-properties-common_0.107_all.deb ... 130s Unpacking software-properties-common (0.107) over (0.105) ... 130s Preparing to unpack .../python3-software-properties_0.107_all.deb ... 130s Unpacking python3-software-properties (0.107) over (0.105) ... 130s Setting up libfwupd3:armhf (2.0.2-2) ... 130s Setting up libatomic1:armhf (14.2.0-9ubuntu1) ... 130s Setting up fwupd (2.0.2-2) ... 131s fwupd-refresh.service is a disabled or a static unit not running, not starting it. 131s fwupd.service is a disabled or a static unit not running, not starting it. 131s Setting up libpython3-stdlib:armhf (3.12.7-1) ... 131s Setting up python3 (3.12.7-1) ... 132s Setting up python3-software-properties (0.107) ... 132s Setting up software-properties-common (0.107) ... 132s Processing triggers for libc-bin (2.40-1ubuntu3) ... 132s Processing triggers for man-db (2.13.0-1) ... 134s Processing triggers for dbus (1.14.10-4ubuntu5) ... 137s Reading package lists... 137s Building dependency tree... 137s Reading state information... 138s Starting pkgProblemResolver with broken count: 0 138s Starting 2 pkgProblemResolver with broken count: 0 138s Done 140s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 142s autopkgtest [09:37:19]: rebooting testbed after setup commands that affected boot 243s autopkgtest [09:39:00]: testbed running kernel: Linux 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 18:12:14 UTC 2 310s autopkgtest [09:40:07]: @@@@@@@@@@@@@@@@@@@@ apt-source tiktoken 337s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (dsc) [2247 B] 337s Get:2 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (tar) [31.6 kB] 337s Get:3 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (diff) [3908 B] 337s gpgv: Signature made Mon Nov 18 15:38:19 2024 UTC 337s gpgv: using RSA key 25E3FF2D7F469DBE7D0D4E50AFCFEC8E669CE1C2 337s gpgv: Can't check signature: No public key 337s dpkg-source: warning: cannot verify inline signature for ./tiktoken_0.8.0-1build1.dsc: no acceptable signature found 337s autopkgtest [09:40:34]: testing package tiktoken version 0.8.0-1build1 345s autopkgtest [09:40:42]: build not needed 352s autopkgtest [09:40:49]: test pybuild-autopkgtest: preparing testbed 356s Reading package lists... 357s Building dependency tree... 357s Reading state information... 357s Starting pkgProblemResolver with broken count: 0 358s Starting 2 pkgProblemResolver with broken count: 0 358s Done 360s The following NEW packages will be installed: 360s autoconf automake autopoint autotools-dev binutils-mingw-w64-i686 360s binutils-mingw-w64-x86-64 build-essential cargo cargo-1.80 cmake cmake-data 360s cpp cpp-14 cpp-14-arm-linux-gnueabihf cpp-arm-linux-gnueabihf debhelper 360s debugedit dh-autoreconf dh-python dh-strip-nondeterminism dwz 360s fontconfig-config fonts-dejavu-core fonts-dejavu-mono g++ g++-14 360s g++-14-arm-linux-gnueabihf g++-arm-linux-gnueabihf gcc gcc-14 360s gcc-14-arm-linux-gnueabihf gcc-arm-linux-gnueabihf gettext intltool-debian 360s libarchive-zip-perl libasan8 libbrotli-dev libbz2-dev libc-dev-bin libc6-dev 360s libcc1-0 libcrypt-dev libdebhelper-perl libexpat1-dev 360s libfile-stripnondeterminism-perl libfontconfig-dev libfontconfig1 360s libfreetype-dev libfreetype6 libgcc-14-dev libgit2-1.7 libgomp1 360s libhttp-parser2.9 libisl23 libjsoncpp25 libllvm18 libllvm19 libmpc3 libpfm4 360s libpkgconf3 libpng-dev libpython3-all-dev libpython3-dev libpython3.12-dev 360s libpython3.12t64 libpython3.13 libpython3.13-dev libpython3.13-minimal 360s libpython3.13-stdlib librhash0 librust-ab-glyph-dev 360s librust-ab-glyph-rasterizer+libm-dev librust-ab-glyph-rasterizer-dev 360s librust-addr2line-dev librust-adler-dev librust-ahash-dev 360s librust-aho-corasick-dev librust-allocator-api2-dev librust-anes-dev 360s librust-anstream-dev librust-anstyle-dev librust-anstyle-parse-dev 360s librust-anstyle-query-dev librust-anyhow-dev librust-approx-dev 360s librust-arbitrary-dev librust-array-init-dev librust-arrayvec-dev 360s librust-async-attributes-dev librust-async-channel-dev 360s librust-async-executor-dev librust-async-fs-dev 360s librust-async-global-executor-dev librust-async-io-dev 360s librust-async-lock-dev librust-async-net-dev librust-async-process-dev 360s librust-async-signal-dev librust-async-std-dev librust-async-task-dev 360s librust-atomic-dev librust-atomic-waker-dev librust-autocfg-dev 360s librust-backtrace-dev librust-base64-dev librust-bit-set+std-dev 360s librust-bit-set-dev librust-bit-vec-dev librust-bitflags-1-dev 360s librust-bitflags-dev librust-bitvec-dev librust-blobby-dev 360s librust-block-buffer-dev librust-blocking-dev librust-bstr-dev 360s librust-bumpalo-dev librust-bytecheck-derive-dev librust-bytecheck-dev 360s librust-bytemuck-derive-dev librust-bytemuck-dev librust-byteorder-dev 360s librust-bytes-dev librust-cast-dev librust-cc-dev librust-cfg-if-0.1-dev 360s librust-cfg-if-dev librust-chrono-dev librust-chrono-tz-build-dev 360s librust-chrono-tz-dev librust-ciborium-dev librust-ciborium-io-dev 360s librust-ciborium-ll-dev librust-clap-builder-dev librust-clap-derive-dev 360s librust-clap-dev librust-clap-lex-dev librust-cmake-dev 360s librust-color-quant-dev librust-colorchoice-dev 360s librust-compiler-builtins+core-dev 360s librust-compiler-builtins+rustc-dep-of-std-dev librust-compiler-builtins-dev 360s librust-concurrent-queue-dev librust-const-cstr-dev librust-const-oid-dev 360s librust-const-random-dev librust-const-random-macro-dev 360s librust-convert-case-dev librust-core-maths-dev librust-cpp-demangle-dev 360s librust-cpufeatures-dev librust-crc32fast-dev librust-criterion-dev 360s librust-critical-section-dev librust-crossbeam-deque-dev 360s librust-crossbeam-epoch+std-dev librust-crossbeam-epoch-dev 360s librust-crossbeam-utils-dev librust-crunchy-dev librust-crypto-common-dev 360s librust-csv-core-dev librust-csv-dev librust-ctor-dev librust-deranged-dev 360s librust-derive-arbitrary-dev librust-derive-more-0.99-dev librust-digest-dev 360s librust-dirs-next-dev librust-dirs-sys-next-dev librust-dlib-dev 360s librust-either-dev librust-env-logger-dev librust-equivalent-dev 360s librust-erased-serde-dev librust-errno-dev librust-eui48-dev 360s librust-event-listener-dev librust-event-listener-strategy-dev 360s librust-eyre+default-dev librust-eyre-dev librust-fallible-iterator-dev 360s librust-fancy-regex-dev librust-fastrand-dev librust-flate2-dev 360s librust-float-ord-dev librust-fnv-dev librust-font-kit-dev 360s librust-freetype-dev librust-freetype-sys-dev librust-funty-dev 360s librust-futures-channel-dev librust-futures-core-dev librust-futures-dev 360s librust-futures-executor-dev librust-futures-io-dev librust-futures-lite-dev 360s librust-futures-macro-dev librust-futures-sink-dev librust-futures-task-dev 360s librust-futures-util-dev librust-generic-array-dev librust-geo-types-dev 360s librust-getrandom-dev librust-ghost-dev librust-gif-dev librust-gimli-dev 360s librust-half-dev librust-hashbrown-dev librust-heck-dev librust-hmac-dev 360s librust-humantime-dev librust-iana-time-zone-dev librust-image-dev 360s librust-indenter-dev librust-indexmap-dev librust-indoc-dev 360s librust-inventory-dev librust-is-terminal-dev librust-itertools-dev 360s librust-itoa-dev librust-jobserver-dev librust-jpeg-decoder-dev 360s librust-js-sys-dev librust-kv-log-macro-dev librust-lazy-static-dev 360s librust-libc-dev librust-libloading-dev librust-libm-dev 360s librust-libwebp-sys-dev librust-libz-sys-dev librust-linux-raw-sys-dev 360s librust-lock-api-dev librust-log-dev librust-md-5-dev librust-md5-asm-dev 360s librust-memchr-dev librust-memmap2-dev librust-memoffset-dev 360s librust-miniz-oxide-dev librust-mio-dev librust-no-panic-dev 360s librust-num-bigint-dev librust-num-complex-dev librust-num-conv-dev 360s librust-num-cpus-dev librust-num-integer-dev librust-num-rational-dev 360s librust-num-threads-dev librust-num-traits-dev librust-object-dev 360s librust-once-cell-dev librust-oorandom-dev librust-owned-ttf-parser-dev 360s librust-owning-ref-dev librust-parking-dev librust-parking-lot-core-dev 360s librust-parking-lot-dev librust-parse-zoneinfo-dev 360s librust-pathfinder-geometry-dev librust-pathfinder-simd-dev 360s librust-phf+uncased-dev librust-phf-codegen-dev librust-phf-dev 360s librust-phf-generator-dev librust-phf-shared+uncased-dev 360s librust-phf-shared-dev librust-pin-project-lite-dev librust-pin-utils-dev 360s librust-pkg-config-dev librust-plotters-backend-dev 360s librust-plotters-bitmap-dev librust-plotters-dev librust-plotters-svg-dev 360s librust-png-dev librust-polling-dev librust-portable-atomic-dev 360s librust-postgres-derive-dev librust-postgres-protocol-dev 360s librust-postgres-types-dev librust-powerfmt-dev librust-powerfmt-macros-dev 360s librust-ppv-lite86-dev librust-proc-macro2-dev librust-proptest-dev 360s librust-ptr-meta-derive-dev librust-ptr-meta-dev 360s librust-pure-rust-locales-dev librust-pyo3-build-config-dev librust-pyo3-dev 360s librust-pyo3-ffi-dev librust-pyo3-macros-backend-dev librust-pyo3-macros-dev 360s librust-python3-dll-a-dev librust-qoi-dev librust-quick-error-dev 360s librust-quickcheck-dev librust-quote-dev librust-radium-dev 360s librust-rand-chacha-dev librust-rand-core+getrandom-dev 360s librust-rand-core+serde-dev librust-rand-core+std-dev librust-rand-core-dev 360s librust-rand-dev librust-rand-xorshift-dev librust-rayon-core-dev 360s librust-rayon-dev librust-regex-automata-dev librust-regex-dev 360s librust-regex-syntax-dev librust-rend-dev librust-rkyv-derive-dev 360s librust-rkyv-dev librust-rust-decimal-dev librust-rustc-demangle-dev 360s librust-rustc-hash-dev librust-rustc-std-workspace-core-dev 360s librust-rustc-version-dev librust-rustix-dev 360s librust-rusty-fork+wait-timeout-dev librust-rusty-fork-dev 360s librust-ruzstd-dev librust-ryu-dev librust-same-file-dev 360s librust-scopeguard-dev librust-seahash-dev librust-semver-dev 360s librust-serde-derive-dev librust-serde-dev librust-serde-fmt-dev 360s librust-serde-json-dev librust-serde-test-dev librust-sha1-asm-dev 360s librust-sha1-dev librust-sha2-asm-dev librust-sha2-dev librust-shlex-dev 360s librust-signal-hook-registry-dev librust-simdutf8-dev librust-siphasher-dev 360s librust-slab-dev librust-slog-dev librust-smallvec-dev librust-smol-dev 360s librust-smol-str-dev librust-socket2-dev librust-spin-dev 360s librust-stable-deref-trait-dev librust-static-assertions-dev 360s librust-stringprep-dev librust-strsim-dev librust-subtle-dev 360s librust-sval-buffer-dev librust-sval-derive-dev librust-sval-dev 360s librust-sval-dynamic-dev librust-sval-fmt-dev librust-sval-ref-dev 360s librust-sval-serde-dev librust-syn-1-dev librust-syn-dev librust-tap-dev 360s librust-target-lexicon-dev librust-tempfile-dev librust-termcolor-dev 360s librust-terminal-size-dev librust-tiff-dev librust-time-core-dev 360s librust-time-dev librust-time-macros-dev librust-tiny-keccak-dev 360s librust-tinytemplate-dev librust-tinyvec+tinyvec-macros-dev 360s librust-tinyvec-dev librust-tinyvec-macros-dev librust-tokio-dev 360s librust-tokio-macros-dev librust-tracing-attributes-dev 360s librust-tracing-core-dev librust-tracing-dev librust-traitobject-dev 360s librust-ttf-parser-dev librust-twox-hash-dev librust-typemap-dev 360s librust-typenum-dev librust-unarray-dev librust-uncased-dev 360s librust-unicase-dev librust-unicode-bidi-dev librust-unicode-ident-dev 360s librust-unicode-normalization-dev librust-unicode-segmentation-dev 360s librust-unicode-width-dev librust-unindent-dev librust-unsafe-any-dev 360s librust-utf8parse-dev librust-uuid-dev librust-valuable-derive-dev 360s librust-valuable-dev librust-value-bag-dev librust-value-bag-serde1-dev 360s librust-value-bag-sval2-dev librust-version-check-dev 360s librust-wait-timeout-dev librust-walkdir-dev 360s librust-wasm-bindgen+default-dev librust-wasm-bindgen+spans-dev 360s librust-wasm-bindgen-backend-dev librust-wasm-bindgen-dev 360s librust-wasm-bindgen-macro+spans-dev librust-wasm-bindgen-macro-dev 360s librust-wasm-bindgen-macro-support+spans-dev 360s librust-wasm-bindgen-macro-support-dev librust-wasm-bindgen-shared-dev 360s librust-web-sys-dev librust-webp-dev librust-weezl-dev librust-winapi-dev 360s librust-winapi-i686-pc-windows-gnu-dev librust-winapi-util-dev 360s librust-winapi-x86-64-pc-windows-gnu-dev librust-wyz-dev 360s librust-yeslogic-fontconfig-sys-dev librust-zerocopy-derive-dev 360s librust-zerocopy-dev librust-zeroize-derive-dev librust-zeroize-dev 360s libsharpyuv-dev libsharpyuv0 libstd-rust-1.80 libstd-rust-1.80-dev 360s libstdc++-14-dev libtool libubsan1 libwebp-dev libwebp7 libwebpdecoder3 360s libwebpdemux2 libwebpmux3 linux-libc-dev llvm llvm-19 llvm-19-linker-tools 360s llvm-19-runtime llvm-runtime m4 pkg-config pkgconf pkgconf-bin po-debconf 360s pybuild-plugin-autopkgtest pybuild-plugin-pyproject python3-all 360s python3-build python3-dateutil python3-hypothesis python3-iniconfig 360s python3-installer python3-packaging python3-pluggy python3-pyproject-hooks 360s python3-pytest python3-regex python3-semantic-version 360s python3-setuptools-rust python3-sortedcontainers python3-tiktoken 360s python3-toml python3-wheel python3.12-dev python3.13 python3.13-minimal 360s rpcsvc-proto rustc rustc-1.80 uuid-dev zlib1g-dev 360s 0 upgraded, 477 newly installed, 0 to remove and 0 not upgraded. 360s Need to get 259 MB of archives. 360s After this operation, 1002 MB of additional disk space will be used. 360s Get:1 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.13-minimal armhf 3.13.0-2 [866 kB] 360s Get:2 http://ftpmaster.internal/ubuntu plucky/main armhf python3.13-minimal armhf 3.13.0-2 [1854 kB] 360s Get:3 http://ftpmaster.internal/ubuntu plucky/main armhf m4 armhf 1.4.19-4build1 [235 kB] 360s Get:4 http://ftpmaster.internal/ubuntu plucky/main armhf autoconf all 2.72-3 [382 kB] 360s Get:5 http://ftpmaster.internal/ubuntu plucky/main armhf autotools-dev all 20220109.1 [44.9 kB] 360s Get:6 http://ftpmaster.internal/ubuntu plucky/main armhf automake all 1:1.16.5-1.3ubuntu1 [558 kB] 361s Get:7 http://ftpmaster.internal/ubuntu plucky/main armhf autopoint all 0.22.5-2 [616 kB] 361s Get:8 http://ftpmaster.internal/ubuntu plucky/main armhf libc-dev-bin armhf 2.40-1ubuntu3 [19.2 kB] 361s Get:9 http://ftpmaster.internal/ubuntu plucky/main armhf linux-libc-dev armhf 6.11.0-8.8 [1628 kB] 361s Get:10 http://ftpmaster.internal/ubuntu plucky/main armhf libcrypt-dev armhf 1:4.4.36-5 [119 kB] 361s Get:11 http://ftpmaster.internal/ubuntu plucky/main armhf rpcsvc-proto armhf 1.4.2-0ubuntu7 [62.2 kB] 361s Get:12 http://ftpmaster.internal/ubuntu plucky/main armhf libc6-dev armhf 2.40-1ubuntu3 [1370 kB] 361s Get:13 http://ftpmaster.internal/ubuntu plucky/main armhf libisl23 armhf 0.27-1 [546 kB] 361s Get:14 http://ftpmaster.internal/ubuntu plucky/main armhf libmpc3 armhf 1.3.1-1build2 [47.1 kB] 361s Get:15 http://ftpmaster.internal/ubuntu plucky/main armhf cpp-14-arm-linux-gnueabihf armhf 14.2.0-9ubuntu1 [9312 kB] 361s Get:16 http://ftpmaster.internal/ubuntu plucky/main armhf cpp-14 armhf 14.2.0-9ubuntu1 [1036 B] 361s Get:17 http://ftpmaster.internal/ubuntu plucky/main armhf cpp-arm-linux-gnueabihf armhf 4:14.1.0-2ubuntu1 [5464 B] 361s Get:18 http://ftpmaster.internal/ubuntu plucky/main armhf cpp armhf 4:14.1.0-2ubuntu1 [22.4 kB] 361s Get:19 http://ftpmaster.internal/ubuntu plucky/main armhf libcc1-0 armhf 14.2.0-9ubuntu1 [43.3 kB] 361s Get:20 http://ftpmaster.internal/ubuntu plucky/main armhf libgomp1 armhf 14.2.0-9ubuntu1 [125 kB] 361s Get:21 http://ftpmaster.internal/ubuntu plucky/main armhf libasan8 armhf 14.2.0-9ubuntu1 [2964 kB] 361s Get:22 http://ftpmaster.internal/ubuntu plucky/main armhf libubsan1 armhf 14.2.0-9ubuntu1 [1177 kB] 361s Get:23 http://ftpmaster.internal/ubuntu plucky/main armhf libgcc-14-dev armhf 14.2.0-9ubuntu1 [874 kB] 361s Get:24 http://ftpmaster.internal/ubuntu plucky/main armhf gcc-14-arm-linux-gnueabihf armhf 14.2.0-9ubuntu1 [18.1 MB] 362s Get:25 http://ftpmaster.internal/ubuntu plucky/main armhf gcc-14 armhf 14.2.0-9ubuntu1 [500 kB] 362s Get:26 http://ftpmaster.internal/ubuntu plucky/main armhf gcc-arm-linux-gnueabihf armhf 4:14.1.0-2ubuntu1 [1222 B] 362s Get:27 http://ftpmaster.internal/ubuntu plucky/main armhf gcc armhf 4:14.1.0-2ubuntu1 [5002 B] 362s Get:28 http://ftpmaster.internal/ubuntu plucky/main armhf libstdc++-14-dev armhf 14.2.0-9ubuntu1 [2556 kB] 362s Get:29 http://ftpmaster.internal/ubuntu plucky/main armhf g++-14-arm-linux-gnueabihf armhf 14.2.0-9ubuntu1 [10.6 MB] 362s Get:30 http://ftpmaster.internal/ubuntu plucky/main armhf g++-14 armhf 14.2.0-9ubuntu1 [20.1 kB] 362s Get:31 http://ftpmaster.internal/ubuntu plucky/main armhf g++-arm-linux-gnueabihf armhf 4:14.1.0-2ubuntu1 [968 B] 362s Get:32 http://ftpmaster.internal/ubuntu plucky/main armhf g++ armhf 4:14.1.0-2ubuntu1 [1084 B] 362s Get:33 http://ftpmaster.internal/ubuntu plucky/main armhf build-essential armhf 12.10ubuntu1 [4928 B] 362s Get:34 http://ftpmaster.internal/ubuntu plucky/main armhf libhttp-parser2.9 armhf 2.9.4-6build1 [21.1 kB] 362s Get:35 http://ftpmaster.internal/ubuntu plucky/main armhf libgit2-1.7 armhf 1.7.2+ds-1ubuntu3 [444 kB] 362s Get:36 http://ftpmaster.internal/ubuntu plucky/main armhf libllvm18 armhf 1:18.1.8-12 [26.6 MB] 364s Get:37 http://ftpmaster.internal/ubuntu plucky/main armhf libstd-rust-1.80 armhf 1.80.1+dfsg0ubuntu1-0ubuntu1 [19.7 MB] 365s Get:38 http://ftpmaster.internal/ubuntu plucky/main armhf libstd-rust-1.80-dev armhf 1.80.1+dfsg0ubuntu1-0ubuntu1 [39.9 MB] 367s Get:39 http://ftpmaster.internal/ubuntu plucky/main armhf rustc-1.80 armhf 1.80.1+dfsg0ubuntu1-0ubuntu1 [3081 kB] 367s Get:40 http://ftpmaster.internal/ubuntu plucky/main armhf cargo-1.80 armhf 1.80.1+dfsg0ubuntu1-0ubuntu1 [5646 kB] 367s Get:41 http://ftpmaster.internal/ubuntu plucky/main armhf libjsoncpp25 armhf 1.9.5-6build1 [75.3 kB] 367s Get:42 http://ftpmaster.internal/ubuntu plucky/main armhf librhash0 armhf 1.4.3-3build1 [143 kB] 367s Get:43 http://ftpmaster.internal/ubuntu plucky/main armhf cmake-data all 3.30.3-1 [2246 kB] 367s Get:44 http://ftpmaster.internal/ubuntu plucky/main armhf cmake armhf 3.30.3-1 [6319 kB] 368s Get:45 http://ftpmaster.internal/ubuntu plucky/main armhf libdebhelper-perl all 13.20ubuntu1 [94.2 kB] 368s Get:46 http://ftpmaster.internal/ubuntu plucky/main armhf libtool all 2.4.7-8 [166 kB] 368s Get:47 http://ftpmaster.internal/ubuntu plucky/main armhf dh-autoreconf all 20 [16.1 kB] 368s Get:48 http://ftpmaster.internal/ubuntu plucky/main armhf libarchive-zip-perl all 1.68-1 [90.2 kB] 368s Get:49 http://ftpmaster.internal/ubuntu plucky/main armhf libfile-stripnondeterminism-perl all 1.14.0-1 [20.1 kB] 368s Get:50 http://ftpmaster.internal/ubuntu plucky/main armhf dh-strip-nondeterminism all 1.14.0-1 [5058 B] 368s Get:51 http://ftpmaster.internal/ubuntu plucky/main armhf debugedit armhf 1:5.1-1 [46.5 kB] 368s Get:52 http://ftpmaster.internal/ubuntu plucky/main armhf dwz armhf 0.15-1build6 [116 kB] 368s Get:53 http://ftpmaster.internal/ubuntu plucky/main armhf gettext armhf 0.22.5-2 [995 kB] 368s Get:54 http://ftpmaster.internal/ubuntu plucky/main armhf intltool-debian all 0.35.0+20060710.6 [23.2 kB] 368s Get:55 http://ftpmaster.internal/ubuntu plucky/main armhf po-debconf all 1.0.21+nmu1 [233 kB] 368s Get:56 http://ftpmaster.internal/ubuntu plucky/main armhf debhelper all 13.20ubuntu1 [893 kB] 368s Get:57 http://ftpmaster.internal/ubuntu plucky/universe armhf dh-python all 6.20241024 [112 kB] 368s Get:58 http://ftpmaster.internal/ubuntu plucky/main armhf fonts-dejavu-mono all 2.37-8 [502 kB] 368s Get:59 http://ftpmaster.internal/ubuntu plucky/main armhf fonts-dejavu-core all 2.37-8 [835 kB] 368s Get:60 http://ftpmaster.internal/ubuntu plucky/main armhf fontconfig-config armhf 2.15.0-1.1ubuntu2 [37.4 kB] 368s Get:61 http://ftpmaster.internal/ubuntu plucky/main armhf libbrotli-dev armhf 1.1.0-2build3 [337 kB] 368s Get:62 http://ftpmaster.internal/ubuntu plucky/main armhf libbz2-dev armhf 1.0.8-6 [30.9 kB] 368s Get:63 http://ftpmaster.internal/ubuntu plucky/main armhf libexpat1-dev armhf 2.6.4-1 [121 kB] 368s Get:64 http://ftpmaster.internal/ubuntu plucky/main armhf libfreetype6 armhf 2.13.3+dfsg-1 [330 kB] 368s Get:65 http://ftpmaster.internal/ubuntu plucky/main armhf libfontconfig1 armhf 2.15.0-1.1ubuntu2 [113 kB] 368s Get:66 http://ftpmaster.internal/ubuntu plucky/main armhf zlib1g-dev armhf 1:1.3.dfsg+really1.3.1-1ubuntu1 [880 kB] 368s Get:67 http://ftpmaster.internal/ubuntu plucky/main armhf libpng-dev armhf 1.6.44-2 [252 kB] 368s Get:68 http://ftpmaster.internal/ubuntu plucky/main armhf libfreetype-dev armhf 2.13.3+dfsg-1 [509 kB] 368s Get:69 http://ftpmaster.internal/ubuntu plucky/main armhf uuid-dev armhf 2.40.2-1ubuntu1 [51.0 kB] 368s Get:70 http://ftpmaster.internal/ubuntu plucky/main armhf libpkgconf3 armhf 1.8.1-4 [26.6 kB] 368s Get:71 http://ftpmaster.internal/ubuntu plucky/main armhf pkgconf-bin armhf 1.8.1-4 [21.2 kB] 368s Get:72 http://ftpmaster.internal/ubuntu plucky/main armhf pkgconf armhf 1.8.1-4 [16.8 kB] 368s Get:73 http://ftpmaster.internal/ubuntu plucky/main armhf libfontconfig-dev armhf 2.15.0-1.1ubuntu2 [143 kB] 368s Get:74 http://ftpmaster.internal/ubuntu plucky/main armhf libllvm19 armhf 1:19.1.2-1ubuntu1 [27.8 MB] 369s Get:75 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.12t64 armhf 3.12.7-3 [2075 kB] 369s Get:76 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.12-dev armhf 3.12.7-3 [4344 kB] 369s Get:77 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf libpython3-dev armhf 3.12.7-1 [10.3 kB] 369s Get:78 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.13-stdlib armhf 3.13.0-2 [1972 kB] 369s Get:79 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.13 armhf 3.13.0-2 [2045 kB] 369s Get:80 http://ftpmaster.internal/ubuntu plucky/main armhf libpython3.13-dev armhf 3.13.0-2 [4254 kB] 370s Get:81 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf libpython3-all-dev armhf 3.12.7-1 [916 B] 370s Get:82 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ab-glyph-rasterizer-dev armhf 0.1.7-1 [12.2 kB] 370s Get:83 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-libm-dev armhf 0.2.8-1 [101 kB] 370s Get:84 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ab-glyph-rasterizer+libm-dev armhf 0.1.7-1 [1062 B] 370s Get:85 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-core-maths-dev armhf 0.1.0-2 [7944 B] 370s Get:86 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ttf-parser-dev armhf 0.24.1-1 [148 kB] 370s Get:87 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-owned-ttf-parser-dev armhf 0.24.0-1 [129 kB] 370s Get:88 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ab-glyph-dev armhf 0.2.28-1 [20.7 kB] 370s Get:89 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cfg-if-dev armhf 1.0.0-1 [10.5 kB] 370s Get:90 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cpp-demangle-dev armhf 0.4.0-1 [66.1 kB] 370s Get:91 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-fallible-iterator-dev armhf 0.3.0-2 [20.3 kB] 370s Get:92 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicode-ident-dev armhf 1.0.13-1 [38.5 kB] 370s Get:93 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-proc-macro2-dev armhf 1.0.86-1 [44.8 kB] 370s Get:94 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-quote-dev armhf 1.0.37-1 [29.5 kB] 370s Get:95 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-syn-dev armhf 2.0.85-1 [219 kB] 370s Get:96 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-derive-arbitrary-dev armhf 1.3.2-1 [12.3 kB] 370s Get:97 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-arbitrary-dev armhf 1.3.2-1 [31.4 kB] 370s Get:98 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-equivalent-dev armhf 1.0.1-1 [8240 B] 370s Get:99 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-critical-section-dev armhf 1.1.3-1 [20.5 kB] 370s Get:100 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-serde-derive-dev armhf 1.0.210-1 [50.1 kB] 370s Get:101 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-serde-dev armhf 1.0.210-2 [66.4 kB] 370s Get:102 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-portable-atomic-dev armhf 1.9.0-4 [124 kB] 370s Get:103 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rustc-std-workspace-core-dev armhf 1.0.0-1 [3020 B] 370s Get:104 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-libc-dev armhf 0.2.161-1 [379 kB] 370s Get:105 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-getrandom-dev armhf 0.2.12-1 [36.4 kB] 370s Get:106 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-smallvec-dev armhf 1.13.2-1 [35.5 kB] 370s Get:107 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-parking-lot-core-dev armhf 0.9.10-1 [32.6 kB] 370s Get:108 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-once-cell-dev armhf 1.20.2-1 [31.9 kB] 370s Get:109 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crunchy-dev armhf 0.2.2-1 [5336 B] 370s Get:110 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tiny-keccak-dev armhf 2.0.2-1 [20.9 kB] 370s Get:111 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-const-random-macro-dev armhf 0.1.16-2 [10.5 kB] 370s Get:112 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-const-random-dev armhf 0.1.17-2 [8588 B] 370s Get:113 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-version-check-dev armhf 0.9.5-1 [16.9 kB] 370s Get:114 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-byteorder-dev armhf 1.5.0-1 [22.4 kB] 370s Get:115 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-zerocopy-derive-dev armhf 0.7.32-2 [29.7 kB] 370s Get:116 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-zerocopy-dev armhf 0.7.32-1 [116 kB] 370s Get:117 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ahash-dev all 0.8.11-8 [37.9 kB] 370s Get:118 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-allocator-api2-dev armhf 0.2.16-1 [54.8 kB] 371s Get:119 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-compiler-builtins-dev armhf 0.1.101-1 [156 kB] 371s Get:120 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-either-dev armhf 1.13.0-1 [20.2 kB] 371s Get:121 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crossbeam-utils-dev armhf 0.8.19-1 [41.1 kB] 371s Get:122 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crossbeam-epoch-dev armhf 0.9.18-1 [42.3 kB] 371s Get:123 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crossbeam-epoch+std-dev armhf 0.9.18-1 [1128 B] 371s Get:124 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crossbeam-deque-dev armhf 0.8.5-1 [22.4 kB] 371s Get:125 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rayon-core-dev armhf 1.12.1-1 [63.7 kB] 371s Get:126 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rayon-dev armhf 1.10.0-1 [149 kB] 371s Get:127 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-hashbrown-dev armhf 0.14.5-5 [110 kB] 371s Get:128 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-indexmap-dev armhf 2.2.6-1 [66.7 kB] 371s Get:129 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-stable-deref-trait-dev armhf 1.2.0-1 [9794 B] 371s Get:130 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-gimli-dev armhf 0.28.1-2 [209 kB] 371s Get:131 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-memmap2-dev armhf 0.9.3-1 [30.8 kB] 371s Get:132 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crc32fast-dev armhf 1.4.2-1 [39.8 kB] 371s Get:133 http://ftpmaster.internal/ubuntu plucky/main armhf pkg-config armhf 1.8.1-4 [7362 B] 371s Get:134 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pkg-config-dev armhf 0.3.27-1 [21.5 kB] 371s Get:135 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-libz-sys-dev armhf 1.1.20-1 [19.8 kB] 371s Get:136 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-adler-dev armhf 1.0.2-2 [15.3 kB] 371s Get:137 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-miniz-oxide-dev armhf 0.7.1-1 [51.5 kB] 371s Get:138 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-flate2-dev armhf 1.0.34-1 [94.5 kB] 371s Get:139 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-derive-dev armhf 2.6.1-2 [11.0 kB] 371s Get:140 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-dev armhf 2.6.1-2 [28.0 kB] 371s Get:141 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-ref-dev armhf 2.6.1-1 [8936 B] 371s Get:142 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-erased-serde-dev armhf 0.3.31-1 [22.7 kB] 371s Get:143 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-serde-fmt-dev all 1.0.3-3 [6956 B] 371s Get:144 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-syn-1-dev armhf 1.0.109-3 [188 kB] 371s Get:145 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-no-panic-dev armhf 0.1.13-1 [11.3 kB] 371s Get:146 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-itoa-dev armhf 1.0.9-1 [13.1 kB] 371s Get:147 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ryu-dev armhf 1.0.15-1 [41.7 kB] 371s Get:148 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-serde-json-dev armhf 1.0.128-1 [128 kB] 371s Get:149 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-serde-test-dev armhf 1.0.171-1 [20.6 kB] 371s Get:150 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-value-bag-serde1-dev armhf 1.9.0-1 [7820 B] 371s Get:151 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-buffer-dev armhf 2.6.1-1 [16.8 kB] 371s Get:152 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-dynamic-dev armhf 2.6.1-1 [9542 B] 371s Get:153 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-fmt-dev armhf 2.6.1-1 [12.0 kB] 371s Get:154 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sval-serde-dev armhf 2.6.1-1 [13.2 kB] 371s Get:155 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-value-bag-sval2-dev armhf 1.9.0-1 [7862 B] 371s Get:156 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-value-bag-dev armhf 1.9.0-1 [37.6 kB] 371s Get:157 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-log-dev armhf 0.4.22-1 [43.0 kB] 371s Get:158 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-memchr-dev armhf 2.7.4-1 [71.8 kB] 371s Get:159 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ppv-lite86-dev armhf 0.2.16-1 [21.9 kB] 371s Get:160 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-core-dev armhf 0.6.4-2 [23.8 kB] 371s Get:161 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-chacha-dev armhf 0.3.1-2 [16.9 kB] 371s Get:162 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-core+getrandom-dev armhf 0.6.4-2 [1052 B] 371s Get:163 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-core+serde-dev armhf 0.6.4-2 [1108 B] 371s Get:164 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-core+std-dev armhf 0.6.4-2 [1052 B] 371s Get:165 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-dev armhf 0.8.5-1 [77.5 kB] 371s Get:166 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicode-segmentation-dev armhf 1.11.0-1 [74.2 kB] 371s Get:167 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-convert-case-dev armhf 0.6.0-2 [19.4 kB] 371s Get:168 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-semver-dev armhf 1.0.23-1 [30.6 kB] 371s Get:169 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rustc-version-dev armhf 0.4.0-1 [13.8 kB] 371s Get:170 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-derive-more-0.99-dev armhf 0.99.18-2 [49.9 kB] 371s Get:171 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cfg-if-0.1-dev armhf 0.1.10-3 [10.5 kB] 371s Get:172 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-blobby-dev armhf 0.3.1-1 [11.3 kB] 371s Get:173 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-typenum-dev armhf 1.17.0-2 [41.2 kB] 371s Get:174 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-zeroize-derive-dev armhf 1.4.2-1 [12.7 kB] 371s Get:175 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-zeroize-dev armhf 1.8.1-1 [21.6 kB] 371s Get:176 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-generic-array-dev armhf 0.14.7-1 [16.9 kB] 371s Get:177 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-block-buffer-dev armhf 0.10.2-2 [12.2 kB] 371s Get:178 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-const-oid-dev armhf 0.9.3-1 [40.9 kB] 371s Get:179 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-crypto-common-dev armhf 0.1.6-1 [10.5 kB] 371s Get:180 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-subtle-dev armhf 2.6.1-1 [16.1 kB] 371s Get:181 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-digest-dev armhf 0.10.7-2 [20.9 kB] 371s Get:182 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-static-assertions-dev armhf 1.1.0-1 [19.0 kB] 371s Get:183 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-twox-hash-dev armhf 1.6.3-1 [21.6 kB] 371s Get:184 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ruzstd-dev armhf 0.5.0-1 [44.6 kB] 371s Get:185 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-object-dev armhf 0.32.2-1 [228 kB] 371s Get:186 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rustc-demangle-dev armhf 0.1.21-1 [27.7 kB] 371s Get:187 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-addr2line-dev armhf 0.21.0-2 [36.4 kB] 372s Get:188 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-aho-corasick-dev armhf 1.1.3-1 [146 kB] 372s Get:189 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bitflags-1-dev armhf 1.3.2-5 [25.3 kB] 372s Get:190 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anes-dev armhf 0.1.6-1 [21.1 kB] 372s Get:191 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anstyle-dev armhf 1.0.8-1 [16.7 kB] 372s Get:192 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-arrayvec-dev armhf 0.7.4-2 [29.9 kB] 372s Get:193 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-utf8parse-dev armhf 0.2.1-1 [15.0 kB] 372s Get:194 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anstyle-parse-dev armhf 0.2.1-1 [17.1 kB] 372s Get:195 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anstyle-query-dev armhf 1.0.0-1 [9768 B] 372s Get:196 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-colorchoice-dev armhf 1.0.0-1 [8336 B] 372s Get:197 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anstream-dev armhf 0.6.15-1 [25.7 kB] 372s Get:198 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-jobserver-dev armhf 0.1.32-1 [29.1 kB] 372s Get:199 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-shlex-dev armhf 1.3.0-1 [20.1 kB] 372s Get:200 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cc-dev armhf 1.1.14-1 [73.6 kB] 372s Get:201 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-backtrace-dev armhf 0.3.69-2 [69.9 kB] 372s Get:202 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-anyhow-dev armhf 1.0.86-1 [44.3 kB] 372s Get:203 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bytecheck-derive-dev armhf 0.6.12-1 [7086 B] 372s Get:204 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ptr-meta-derive-dev armhf 0.1.4-1 [3964 B] 372s Get:205 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ptr-meta-dev armhf 0.1.4-1 [7342 B] 372s Get:206 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-simdutf8-dev armhf 0.1.4-4 [27.2 kB] 372s Get:207 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bytemuck-derive-dev armhf 1.5.0-2 [18.7 kB] 372s Get:208 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bytemuck-dev armhf 1.14.0-1 [42.7 kB] 372s Get:209 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-atomic-dev armhf 0.6.0-1 [15.5 kB] 372s Get:210 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-md5-asm-dev armhf 0.5.0-2 [7512 B] 372s Get:211 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-md-5-dev armhf 0.10.6-1 [17.5 kB] 372s Get:212 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cpufeatures-dev armhf 0.2.11-1 [14.9 kB] 372s Get:213 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sha1-asm-dev armhf 0.5.1-2 [8058 B] 372s Get:214 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sha1-dev armhf 0.10.6-1 [16.0 kB] 372s Get:215 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-slog-dev armhf 2.7.0-1 [44.0 kB] 372s Get:216 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-uuid-dev armhf 1.10.0-1 [44.2 kB] 372s Get:217 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bytecheck-dev armhf 0.6.12-1 [10.2 kB] 372s Get:218 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-autocfg-dev armhf 1.1.0-1 [15.1 kB] 372s Get:219 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-traits-dev armhf 0.2.19-2 [46.2 kB] 372s Get:220 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-funty-dev armhf 2.0.0-1 [13.8 kB] 372s Get:221 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-radium-dev armhf 1.1.0-1 [14.9 kB] 372s Get:222 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tap-dev armhf 1.0.1-1 [12.7 kB] 372s Get:223 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-traitobject-dev armhf 0.1.0-1 [4540 B] 372s Get:224 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unsafe-any-dev armhf 0.4.2-2 [4622 B] 372s Get:225 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-typemap-dev armhf 0.3.3-2 [6724 B] 372s Get:226 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wyz-dev armhf 0.5.1-1 [19.7 kB] 372s Get:227 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bitvec-dev armhf 1.0.1-1 [179 kB] 372s Get:228 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bytes-dev armhf 1.8.0-1 [56.9 kB] 372s Get:229 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rend-dev armhf 0.4.0-1 [10.3 kB] 372s Get:230 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rkyv-derive-dev armhf 0.7.44-1 [17.5 kB] 372s Get:231 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-seahash-dev armhf 4.1.0-1 [25.1 kB] 372s Get:232 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-smol-str-dev armhf 0.2.0-1 [15.2 kB] 372s Get:233 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tinyvec-dev armhf 1.6.0-2 [37.7 kB] 373s Get:234 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tinyvec-macros-dev armhf 0.1.0-1 [3852 B] 373s Get:235 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tinyvec+tinyvec-macros-dev armhf 1.6.0-2 [1124 B] 373s Get:236 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rkyv-dev armhf 0.7.44-1 [94.4 kB] 373s Get:237 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-complex-dev armhf 0.4.6-2 [30.8 kB] 373s Get:238 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-approx-dev armhf 0.5.1-1 [16.0 kB] 373s Get:239 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-array-init-dev armhf 2.0.1-1 [12.3 kB] 373s Get:240 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-attributes-dev all 1.1.2-6 [6756 B] 373s Get:241 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-concurrent-queue-dev armhf 2.5.0-4 [23.9 kB] 373s Get:242 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-parking-dev armhf 2.2.0-1 [11.6 kB] 373s Get:243 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pin-project-lite-dev armhf 0.2.13-1 [30.2 kB] 373s Get:244 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-event-listener-dev all 5.3.1-8 [29.6 kB] 373s Get:245 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-event-listener-strategy-dev armhf 0.5.2-3 [12.6 kB] 373s Get:246 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-core-dev armhf 0.3.30-1 [16.7 kB] 373s Get:247 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-channel-dev all 2.3.1-8 [13.1 kB] 373s Get:248 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-task-dev all 4.7.1-3 [29.4 kB] 373s Get:249 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-fastrand-dev armhf 2.1.1-1 [17.8 kB] 373s Get:250 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-io-dev armhf 0.3.31-1 [11.2 kB] 373s Get:251 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-lite-dev armhf 2.3.0-2 [38.6 kB] 373s Get:252 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-slab-dev armhf 0.4.9-1 [21.2 kB] 373s Get:253 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-executor-dev all 1.13.1-1 [18.7 kB] 373s Get:254 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-lock-dev all 3.4.0-4 [29.3 kB] 373s Get:255 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-atomic-waker-dev armhf 1.1.2-1 [14.3 kB] 373s Get:256 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tracing-attributes-dev armhf 0.1.27-1 [33.3 kB] 373s Get:257 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-valuable-derive-dev armhf 0.1.0-1 [5942 B] 373s Get:258 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-valuable-dev armhf 0.1.0-4 [23.5 kB] 373s Get:259 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tracing-core-dev armhf 0.1.32-1 [53.8 kB] 373s Get:260 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tracing-dev armhf 0.1.40-1 [69.5 kB] 373s Get:261 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-blocking-dev all 1.6.1-5 [17.5 kB] 373s Get:262 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-fs-dev all 2.1.2-4 [15.3 kB] 373s Get:263 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bitflags-dev armhf 2.6.0-1 [41.1 kB] 373s Get:264 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-compiler-builtins+core-dev armhf 0.1.101-1 [1090 B] 373s Get:265 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-compiler-builtins+rustc-dep-of-std-dev armhf 0.1.101-1 [1104 B] 373s Get:266 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-errno-dev armhf 0.3.8-1 [13.0 kB] 373s Get:267 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-linux-raw-sys-dev armhf 0.4.14-1 [138 kB] 373s Get:268 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rustix-dev armhf 0.38.37-1 [272 kB] 373s Get:269 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-polling-dev armhf 3.4.0-1 [47.8 kB] 373s Get:270 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-io-dev armhf 2.3.3-4 [41.0 kB] 373s Get:271 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-mio-dev armhf 1.0.2-2 [87.6 kB] 373s Get:272 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-owning-ref-dev armhf 0.4.1-1 [13.7 kB] 373s Get:273 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-scopeguard-dev armhf 1.2.0-1 [13.3 kB] 373s Get:274 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-lock-api-dev armhf 0.4.12-1 [22.9 kB] 373s Get:275 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-parking-lot-dev armhf 0.12.3-1 [38.7 kB] 373s Get:276 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-signal-hook-registry-dev armhf 1.4.0-1 [19.2 kB] 373s Get:277 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-socket2-dev armhf 0.5.7-1 [48.3 kB] 373s Get:278 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tokio-macros-dev armhf 2.4.0-2 [14.0 kB] 373s Get:279 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tokio-dev armhf 1.39.3-3 [561 kB] 374s Get:280 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-global-executor-dev armhf 2.4.1-5 [14.6 kB] 374s Get:281 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-net-dev all 2.0.0-4 [14.6 kB] 374s Get:282 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-signal-dev armhf 0.2.10-1 [16.0 kB] 374s Get:283 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-process-dev all 2.3.0-1 [21.2 kB] 374s Get:284 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-kv-log-macro-dev all 1.0.8-4 [7290 B] 374s Get:285 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pin-utils-dev armhf 0.1.0-1 [9340 B] 374s Get:286 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-async-std-dev all 1.13.0-1 [170 kB] 374s Get:287 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-base64-dev armhf 0.21.7-1 [65.1 kB] 374s Get:288 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bit-vec-dev armhf 0.6.3-1 [21.1 kB] 374s Get:289 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bit-set-dev armhf 0.5.2-1 [15.7 kB] 374s Get:290 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bit-set+std-dev armhf 0.5.2-1 [1084 B] 374s Get:291 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-regex-syntax-dev armhf 0.8.5-1 [203 kB] 374s Get:292 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-regex-automata-dev armhf 0.4.9-1 [425 kB] 374s Get:293 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bstr-dev armhf 1.7.0-2build1 [271 kB] 374s Get:294 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-bumpalo-dev armhf 3.16.0-1 [75.7 kB] 374s Get:295 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cast-dev armhf 0.3.0-1 [13.1 kB] 374s Get:296 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-iana-time-zone-dev armhf 0.1.60-1 [25.1 kB] 374s Get:297 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-shared-dev armhf 0.2.87-1 [9090 B] 374s Get:298 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-backend-dev armhf 0.2.87-1 [27.0 kB] 374s Get:299 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-macro-support-dev armhf 0.2.87-1 [21.2 kB] 374s Get:300 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-macro-dev armhf 0.2.87-1 [16.6 kB] 374s Get:301 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-dev armhf 0.2.87-1 [157 kB] 374s Get:302 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-macro-support+spans-dev armhf 0.2.87-1 [1074 B] 374s Get:303 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen-macro+spans-dev armhf 0.2.87-1 [1058 B] 374s Get:304 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen+spans-dev armhf 0.2.87-1 [1038 B] 374s Get:305 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wasm-bindgen+default-dev armhf 0.2.87-1 [1046 B] 374s Get:306 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-js-sys-dev armhf 0.3.64-1 [71.9 kB] 374s Get:307 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pure-rust-locales-dev armhf 0.8.1-1 [112 kB] 374s Get:308 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-chrono-dev armhf 0.4.38-2 [172 kB] 375s Get:309 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-regex-dev armhf 1.10.6-1 [199 kB] 375s Get:310 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-parse-zoneinfo-dev armhf 0.3.0-1 [71.0 kB] 375s Get:311 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-siphasher-dev armhf 0.3.10-1 [12.0 kB] 375s Get:312 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf-shared-dev armhf 0.11.2-1 [15.6 kB] 375s Get:313 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf-dev armhf 0.11.2-1 [21.6 kB] 375s Get:314 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-uncased-dev armhf 0.9.6-2 [12.2 kB] 375s Get:315 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf-shared+uncased-dev armhf 0.11.2-1 [1028 B] 375s Get:316 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf+uncased-dev armhf 0.11.2-1 [1028 B] 375s Get:317 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ciborium-io-dev armhf 0.2.2-1 [8178 B] 375s Get:318 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-half-dev armhf 1.8.2-4 [34.8 kB] 375s Get:319 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ciborium-ll-dev armhf 0.2.2-1 [15.8 kB] 375s Get:320 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ciborium-dev armhf 0.2.2-2 [32.6 kB] 375s Get:321 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-clap-lex-dev armhf 0.7.2-2 [14.3 kB] 375s Get:322 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-strsim-dev armhf 0.11.1-1 [15.9 kB] 375s Get:323 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-terminal-size-dev armhf 0.3.0-2 [12.6 kB] 375s Get:324 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicase-dev armhf 2.7.0-1 [19.4 kB] 375s Get:325 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicode-width-dev armhf 0.1.14-1 [196 kB] 375s Get:326 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-clap-builder-dev armhf 4.5.15-2 [135 kB] 375s Get:327 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-heck-dev armhf 0.4.1-1 [13.3 kB] 375s Get:328 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-clap-derive-dev armhf 4.5.13-2 [29.3 kB] 375s Get:329 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-clap-dev armhf 4.5.16-1 [52.3 kB] 375s Get:330 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-csv-core-dev armhf 0.1.11-1 [25.9 kB] 375s Get:331 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-csv-dev armhf 1.3.0-1 [729 kB] 375s Get:332 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-sink-dev armhf 0.3.31-1 [10.1 kB] 375s Get:333 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-channel-dev armhf 0.3.30-1 [31.8 kB] 375s Get:334 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-task-dev armhf 0.3.30-1 [13.5 kB] 375s Get:335 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-macro-dev armhf 0.3.30-1 [13.3 kB] 375s Get:336 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-util-dev armhf 0.3.30-2 [127 kB] 375s Get:337 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-cpus-dev armhf 1.16.0-1 [18.1 kB] 375s Get:338 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-executor-dev armhf 0.3.30-1 [19.8 kB] 375s Get:339 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-futures-dev armhf 0.3.30-2 [53.2 kB] 376s Get:340 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-is-terminal-dev armhf 0.4.13-1 [8264 B] 376s Get:341 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-itertools-dev armhf 0.10.5-1 [101 kB] 376s Get:342 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-oorandom-dev armhf 11.1.3-1 [11.3 kB] 376s Get:343 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-winapi-i686-pc-windows-gnu-dev armhf 0.4.0-1 [3652 B] 376s Get:344 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-winapi-x86-64-pc-windows-gnu-dev armhf 0.4.0-1 [3660 B] 376s Get:345 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-winapi-dev armhf 0.3.9-1 [953 kB] 376s Get:346 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-dirs-sys-next-dev armhf 0.1.1-1 [12.1 kB] 376s Get:347 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-dirs-next-dev armhf 2.0.0-1 [13.1 kB] 376s Get:348 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-float-ord-dev armhf 0.3.2-1 [9400 B] 376s Get:349 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-cmake-dev armhf 0.1.45-1 [16.0 kB] 376s Get:350 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-freetype-sys-dev armhf 0.13.1-1 [11.8 kB] 376s Get:351 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-freetype-dev armhf 0.7.0-4 [20.4 kB] 376s Get:352 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-spin-dev armhf 0.9.8-4 [33.4 kB] 376s Get:353 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-lazy-static-dev armhf 1.5.0-1 [14.2 kB] 376s Get:354 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pathfinder-simd-dev armhf 0.5.2-1 [20.1 kB] 376s Get:355 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pathfinder-geometry-dev armhf 0.5.1-1 [13.2 kB] 376s Get:356 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-winapi-util-dev armhf 0.1.6-1 [14.0 kB] 376s Get:357 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-same-file-dev armhf 1.0.6-1 [11.5 kB] 376s Get:358 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-walkdir-dev armhf 2.5.0-1 [24.5 kB] 376s Get:359 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-const-cstr-dev armhf 0.3.0-1 [9070 B] 376s Get:360 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-libloading-dev armhf 0.8.5-1 [29.2 kB] 376s Get:361 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-dlib-dev armhf 0.5.2-2 [7970 B] 376s Get:362 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-yeslogic-fontconfig-sys-dev armhf 3.0.1-1 [8110 B] 376s Get:363 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-font-kit-dev armhf 0.11.0-2 [56.2 kB] 376s Get:364 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-color-quant-dev armhf 1.1.0-1 [8462 B] 376s Get:365 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-weezl-dev armhf 0.1.5-1 [30.3 kB] 376s Get:366 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-gif-dev armhf 0.11.3-1 [31.9 kB] 376s Get:367 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-jpeg-decoder-dev armhf 0.3.0-1 [717 kB] 376s Get:368 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-integer-dev armhf 0.1.46-1 [22.6 kB] 376s Get:369 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-humantime-dev armhf 2.1.0-1 [18.2 kB] 376s Get:370 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-termcolor-dev armhf 1.4.1-1 [19.7 kB] 376s Get:371 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-env-logger-dev armhf 0.10.2-2 [34.4 kB] 376s Get:372 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-quickcheck-dev armhf 1.0.3-3 [27.9 kB] 376s Get:373 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-bigint-dev armhf 0.4.6-1 [84.9 kB] 376s Get:374 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-rational-dev armhf 0.4.2-1 [28.7 kB] 376s Get:375 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-png-dev armhf 0.17.7-3 [63.4 kB] 376s Get:376 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-qoi-dev armhf 0.4.1-2 [56.7 kB] 377s Get:377 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tiff-dev armhf 0.9.0-1 [1413 kB] 377s Get:378 http://ftpmaster.internal/ubuntu plucky/main armhf libsharpyuv0 armhf 1.4.0-0.1 [16.3 kB] 377s Get:379 http://ftpmaster.internal/ubuntu plucky/main armhf libwebp7 armhf 1.4.0-0.1 [184 kB] 377s Get:380 http://ftpmaster.internal/ubuntu plucky/main armhf libwebpdemux2 armhf 1.4.0-0.1 [11.8 kB] 377s Get:381 http://ftpmaster.internal/ubuntu plucky/main armhf libwebpmux3 armhf 1.4.0-0.1 [22.5 kB] 377s Get:382 http://ftpmaster.internal/ubuntu plucky/main armhf libwebpdecoder3 armhf 1.4.0-0.1 [93.8 kB] 377s Get:383 http://ftpmaster.internal/ubuntu plucky/main armhf libsharpyuv-dev armhf 1.4.0-0.1 [16.8 kB] 377s Get:384 http://ftpmaster.internal/ubuntu plucky/main armhf libwebp-dev armhf 1.4.0-0.1 [316 kB] 377s Get:385 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-libwebp-sys-dev armhf 0.9.5-1build1 [1357 kB] 377s Get:386 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-webp-dev armhf 0.2.6-1 [1846 kB] 378s Get:387 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-image-dev armhf 0.24.7-2 [229 kB] 378s Get:388 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-plotters-backend-dev armhf 0.3.7-1 [15.7 kB] 378s Get:389 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-plotters-bitmap-dev armhf 0.3.3-3 [17.1 kB] 378s Get:390 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-plotters-svg-dev armhf 0.3.5-1 [9258 B] 378s Get:391 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-web-sys-dev armhf 0.3.64-2 [581 kB] 378s Get:392 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-plotters-dev armhf 0.3.5-4 [118 kB] 378s Get:393 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-smol-dev all 2.0.2-1 [205 kB] 378s Get:394 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tinytemplate-dev armhf 1.2.1-1 [26.8 kB] 378s Get:395 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-criterion-dev all 0.5.1-6 [104 kB] 378s Get:396 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf-generator-dev armhf 0.11.2-2 [12.3 kB] 378s Get:397 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-phf-codegen-dev armhf 0.11.2-1 [14.3 kB] 378s Get:398 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-chrono-tz-build-dev armhf 0.2.1-1 [12.1 kB] 378s Get:399 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-chrono-tz-dev armhf 0.8.6-2 [513 kB] 378s Get:400 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ctor-dev armhf 0.1.26-1 [12.0 kB] 378s Get:401 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-powerfmt-macros-dev armhf 0.1.0-1 [10.5 kB] 378s Get:402 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-powerfmt-dev armhf 0.2.0-1 [16.5 kB] 378s Get:403 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-deranged-dev armhf 0.3.11-1 [18.4 kB] 378s Get:404 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-eui48-dev armhf 1.1.0-2 [16.1 kB] 378s Get:405 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-indenter-dev armhf 0.3.3-1 [8646 B] 378s Get:406 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-eyre-dev armhf 0.6.12-1 [38.0 kB] 378s Get:407 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-eyre+default-dev armhf 0.6.12-1 [1050 B] 378s Get:408 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-fancy-regex-dev armhf 0.11.0-2 [54.7 kB] 378s Get:409 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-fnv-dev armhf 1.0.7-1 [12.8 kB] 378s Get:410 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-geo-types-dev armhf 0.7.11-2 [32.8 kB] 378s Get:411 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-ghost-dev armhf 0.1.5-1 [16.1 kB] 378s Get:412 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-hmac-dev armhf 0.12.1-1 [43.9 kB] 378s Get:413 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-indoc-dev armhf 2.0.5-1 [16.7 kB] 378s Get:414 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-inventory-dev armhf 0.3.2-1 [13.5 kB] 378s Get:415 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-memoffset-dev armhf 0.8.0-1 [10.9 kB] 378s Get:416 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-conv-dev armhf 0.1.0-1 [8990 B] 378s Get:417 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-num-threads-dev armhf 0.1.7-1 [9152 B] 378s Get:418 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-postgres-derive-dev armhf 0.4.5-1 [13.4 kB] 379s Get:419 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sha2-asm-dev armhf 0.6.2-2 [14.4 kB] 379s Get:420 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-sha2-dev armhf 0.10.8-1 [25.6 kB] 379s Get:421 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicode-bidi-dev armhf 0.3.13-1 [39.8 kB] 379s Get:422 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unicode-normalization-dev armhf 0.1.22-1 [104 kB] 379s Get:423 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-stringprep-dev armhf 0.1.2-1 [16.5 kB] 379s Get:424 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-postgres-protocol-dev armhf 0.6.6-2 [25.9 kB] 379s Get:425 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-time-core-dev armhf 0.1.2-1 [9134 B] 379s Get:426 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-time-macros-dev armhf 0.2.16-1 [25.1 kB] 379s Get:427 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-time-dev armhf 0.3.36-2 [99.4 kB] 379s Get:428 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-postgres-types-dev armhf 0.2.6-2 [30.1 kB] 379s Get:429 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rand-xorshift-dev armhf 0.3.0-2 [10.9 kB] 379s Get:430 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-quick-error-dev armhf 2.0.1-1 [15.6 kB] 379s Get:431 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-tempfile-dev armhf 3.13.0-1 [35.0 kB] 379s Get:432 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rusty-fork-dev armhf 0.3.0-1 [20.4 kB] 379s Get:433 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-wait-timeout-dev armhf 0.2.0-1 [14.2 kB] 379s Get:434 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rusty-fork+wait-timeout-dev armhf 0.3.0-1 [1132 B] 379s Get:435 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unarray-dev armhf 0.1.4-1 [14.6 kB] 379s Get:436 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-proptest-dev armhf 1.5.0-2 [171 kB] 379s Get:437 http://ftpmaster.internal/ubuntu plucky/universe armhf llvm-19-runtime armhf 1:19.1.2-1ubuntu1 [530 kB] 379s Get:438 http://ftpmaster.internal/ubuntu plucky/universe armhf llvm-runtime armhf 1:19.0-60~exp1 [5608 B] 379s Get:439 http://ftpmaster.internal/ubuntu plucky/universe armhf llvm-19-linker-tools armhf 1:19.1.2-1ubuntu1 [1160 kB] 379s Get:440 http://ftpmaster.internal/ubuntu plucky/universe armhf libpfm4 armhf 4.13.0+git83-g91970fe-1 [62.8 kB] 379s Get:441 http://ftpmaster.internal/ubuntu plucky/universe armhf llvm-19 armhf 1:19.1.2-1ubuntu1 [17.3 MB] 381s Get:442 http://ftpmaster.internal/ubuntu plucky/universe armhf llvm armhf 1:19.0-60~exp1 [4146 B] 381s Get:443 http://ftpmaster.internal/ubuntu plucky/universe armhf binutils-mingw-w64-x86-64 armhf 2.43.1-4ubuntu1+12 [2771 kB] 381s Get:444 http://ftpmaster.internal/ubuntu plucky/universe armhf binutils-mingw-w64-i686 armhf 2.43.1-4ubuntu1+12 [2446 kB] 381s Get:445 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-python3-dll-a-dev armhf 0.2.10-1 [31.6 kB] 381s Get:446 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-target-lexicon-dev armhf 0.12.14-1 [25.1 kB] 381s Get:447 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pyo3-build-config-dev armhf 0.22.6-1 [30.8 kB] 381s Get:448 http://ftpmaster.internal/ubuntu plucky/main armhf python3.12-dev armhf 3.12.7-3 [505 kB] 381s Get:449 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pyo3-ffi-dev armhf 0.22.6-1build1 [62.6 kB] 381s Get:450 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pyo3-macros-backend-dev armhf 0.22.6-1 [58.5 kB] 381s Get:451 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pyo3-macros-dev armhf 0.22.6-1 [10.4 kB] 381s Get:452 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rust-decimal-dev armhf 1.36.0-1 [114 kB] 381s Get:453 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-unindent-dev armhf 0.2.3-1 [9188 B] 381s Get:454 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-pyo3-dev armhf 0.22.6-1 [415 kB] 381s Get:455 http://ftpmaster.internal/ubuntu plucky/universe armhf librust-rustc-hash-dev armhf 1.1.0-1 [10.8 kB] 381s Get:456 http://ftpmaster.internal/ubuntu plucky/universe armhf pybuild-plugin-autopkgtest all 6.20241024 [1746 B] 381s Get:457 http://ftpmaster.internal/ubuntu plucky/main armhf python3-packaging all 24.2-1 [51.5 kB] 381s Get:458 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-pyproject-hooks all 1.2.0-1 [10.2 kB] 381s Get:459 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-toml all 0.10.2-1 [16.5 kB] 381s Get:460 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-wheel all 0.45.1-1 [57.7 kB] 381s Get:461 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-build all 1.2.2-1 [31.0 kB] 381s Get:462 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-installer all 0.7.0+dfsg1-3 [17.4 kB] 381s Get:463 http://ftpmaster.internal/ubuntu plucky/universe armhf pybuild-plugin-pyproject all 6.20241024 [1728 B] 381s Get:464 http://ftpmaster.internal/ubuntu plucky/main armhf python3.13 armhf 3.13.0-2 [719 kB] 381s Get:465 http://ftpmaster.internal/ubuntu plucky-proposed/main armhf python3-all armhf 3.12.7-1 [890 B] 381s Get:466 http://ftpmaster.internal/ubuntu plucky/main armhf python3-dateutil all 2.9.0-3 [80.2 kB] 381s Get:467 http://ftpmaster.internal/ubuntu plucky/main armhf python3-sortedcontainers all 2.4.0-2 [27.6 kB] 381s Get:468 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-hypothesis all 6.119.3-1 [329 kB] 381s Get:469 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-iniconfig all 1.1.1-2 [6024 B] 381s Get:470 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-pluggy all 1.5.0-1 [21.0 kB] 381s Get:471 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-pytest all 8.3.3-1 [251 kB] 381s Get:472 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-regex armhf 0.1.20240724-1build1 [274 kB] 381s Get:473 http://ftpmaster.internal/ubuntu plucky/main armhf python3-semantic-version all 2.10.0-2 [15.1 kB] 381s Get:474 http://ftpmaster.internal/ubuntu plucky/main armhf rustc armhf 1.80.1ubuntu2 [2754 B] 381s Get:475 http://ftpmaster.internal/ubuntu plucky/main armhf cargo armhf 1.80.1ubuntu2 [2242 B] 381s Get:476 http://ftpmaster.internal/ubuntu plucky/universe armhf python3-setuptools-rust all 1.9.0+dfsg-2 [23.1 kB] 381s Get:477 http://ftpmaster.internal/ubuntu plucky-proposed/universe armhf python3-tiktoken armhf 0.8.0-1build1 [706 kB] 383s Fetched 259 MB in 22s (12.0 MB/s) 383s Selecting previously unselected package libpython3.13-minimal:armhf. 383s (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 ... 59970 files and directories currently installed.) 383s Preparing to unpack .../000-libpython3.13-minimal_3.13.0-2_armhf.deb ... 383s Unpacking libpython3.13-minimal:armhf (3.13.0-2) ... 383s Selecting previously unselected package python3.13-minimal. 383s Preparing to unpack .../001-python3.13-minimal_3.13.0-2_armhf.deb ... 383s Unpacking python3.13-minimal (3.13.0-2) ... 383s Selecting previously unselected package m4. 383s Preparing to unpack .../002-m4_1.4.19-4build1_armhf.deb ... 383s Unpacking m4 (1.4.19-4build1) ... 383s Selecting previously unselected package autoconf. 383s Preparing to unpack .../003-autoconf_2.72-3_all.deb ... 383s Unpacking autoconf (2.72-3) ... 383s Selecting previously unselected package autotools-dev. 383s Preparing to unpack .../004-autotools-dev_20220109.1_all.deb ... 383s Unpacking autotools-dev (20220109.1) ... 384s Selecting previously unselected package automake. 384s Preparing to unpack .../005-automake_1%3a1.16.5-1.3ubuntu1_all.deb ... 384s Unpacking automake (1:1.16.5-1.3ubuntu1) ... 384s Selecting previously unselected package autopoint. 384s Preparing to unpack .../006-autopoint_0.22.5-2_all.deb ... 384s Unpacking autopoint (0.22.5-2) ... 384s Selecting previously unselected package libc-dev-bin. 384s Preparing to unpack .../007-libc-dev-bin_2.40-1ubuntu3_armhf.deb ... 384s Unpacking libc-dev-bin (2.40-1ubuntu3) ... 384s Selecting previously unselected package linux-libc-dev:armhf. 384s Preparing to unpack .../008-linux-libc-dev_6.11.0-8.8_armhf.deb ... 384s Unpacking linux-libc-dev:armhf (6.11.0-8.8) ... 384s Selecting previously unselected package libcrypt-dev:armhf. 384s Preparing to unpack .../009-libcrypt-dev_1%3a4.4.36-5_armhf.deb ... 384s Unpacking libcrypt-dev:armhf (1:4.4.36-5) ... 384s Selecting previously unselected package rpcsvc-proto. 384s Preparing to unpack .../010-rpcsvc-proto_1.4.2-0ubuntu7_armhf.deb ... 384s Unpacking rpcsvc-proto (1.4.2-0ubuntu7) ... 384s Selecting previously unselected package libc6-dev:armhf. 384s Preparing to unpack .../011-libc6-dev_2.40-1ubuntu3_armhf.deb ... 384s Unpacking libc6-dev:armhf (2.40-1ubuntu3) ... 384s Selecting previously unselected package libisl23:armhf. 384s Preparing to unpack .../012-libisl23_0.27-1_armhf.deb ... 384s Unpacking libisl23:armhf (0.27-1) ... 384s Selecting previously unselected package libmpc3:armhf. 384s Preparing to unpack .../013-libmpc3_1.3.1-1build2_armhf.deb ... 384s Unpacking libmpc3:armhf (1.3.1-1build2) ... 384s Selecting previously unselected package cpp-14-arm-linux-gnueabihf. 384s Preparing to unpack .../014-cpp-14-arm-linux-gnueabihf_14.2.0-9ubuntu1_armhf.deb ... 384s Unpacking cpp-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package cpp-14. 385s Preparing to unpack .../015-cpp-14_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking cpp-14 (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package cpp-arm-linux-gnueabihf. 385s Preparing to unpack .../016-cpp-arm-linux-gnueabihf_4%3a14.1.0-2ubuntu1_armhf.deb ... 385s Unpacking cpp-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 385s Selecting previously unselected package cpp. 385s Preparing to unpack .../017-cpp_4%3a14.1.0-2ubuntu1_armhf.deb ... 385s Unpacking cpp (4:14.1.0-2ubuntu1) ... 385s Selecting previously unselected package libcc1-0:armhf. 385s Preparing to unpack .../018-libcc1-0_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking libcc1-0:armhf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package libgomp1:armhf. 385s Preparing to unpack .../019-libgomp1_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking libgomp1:armhf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package libasan8:armhf. 385s Preparing to unpack .../020-libasan8_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking libasan8:armhf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package libubsan1:armhf. 385s Preparing to unpack .../021-libubsan1_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking libubsan1:armhf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package libgcc-14-dev:armhf. 385s Preparing to unpack .../022-libgcc-14-dev_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking libgcc-14-dev:armhf (14.2.0-9ubuntu1) ... 385s Selecting previously unselected package gcc-14-arm-linux-gnueabihf. 385s Preparing to unpack .../023-gcc-14-arm-linux-gnueabihf_14.2.0-9ubuntu1_armhf.deb ... 385s Unpacking gcc-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 386s Selecting previously unselected package gcc-14. 386s Preparing to unpack .../024-gcc-14_14.2.0-9ubuntu1_armhf.deb ... 386s Unpacking gcc-14 (14.2.0-9ubuntu1) ... 386s Selecting previously unselected package gcc-arm-linux-gnueabihf. 386s Preparing to unpack .../025-gcc-arm-linux-gnueabihf_4%3a14.1.0-2ubuntu1_armhf.deb ... 386s Unpacking gcc-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 386s Selecting previously unselected package gcc. 386s Preparing to unpack .../026-gcc_4%3a14.1.0-2ubuntu1_armhf.deb ... 386s Unpacking gcc (4:14.1.0-2ubuntu1) ... 386s Selecting previously unselected package libstdc++-14-dev:armhf. 386s Preparing to unpack .../027-libstdc++-14-dev_14.2.0-9ubuntu1_armhf.deb ... 386s Unpacking libstdc++-14-dev:armhf (14.2.0-9ubuntu1) ... 387s Selecting previously unselected package g++-14-arm-linux-gnueabihf. 387s Preparing to unpack .../028-g++-14-arm-linux-gnueabihf_14.2.0-9ubuntu1_armhf.deb ... 387s Unpacking g++-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 387s Selecting previously unselected package g++-14. 387s Preparing to unpack .../029-g++-14_14.2.0-9ubuntu1_armhf.deb ... 387s Unpacking g++-14 (14.2.0-9ubuntu1) ... 387s Selecting previously unselected package g++-arm-linux-gnueabihf. 387s Preparing to unpack .../030-g++-arm-linux-gnueabihf_4%3a14.1.0-2ubuntu1_armhf.deb ... 387s Unpacking g++-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 387s Selecting previously unselected package g++. 387s Preparing to unpack .../031-g++_4%3a14.1.0-2ubuntu1_armhf.deb ... 387s Unpacking g++ (4:14.1.0-2ubuntu1) ... 387s Selecting previously unselected package build-essential. 387s Preparing to unpack .../032-build-essential_12.10ubuntu1_armhf.deb ... 387s Unpacking build-essential (12.10ubuntu1) ... 387s Selecting previously unselected package libhttp-parser2.9:armhf. 387s Preparing to unpack .../033-libhttp-parser2.9_2.9.4-6build1_armhf.deb ... 387s Unpacking libhttp-parser2.9:armhf (2.9.4-6build1) ... 387s Selecting previously unselected package libgit2-1.7:armhf. 387s Preparing to unpack .../034-libgit2-1.7_1.7.2+ds-1ubuntu3_armhf.deb ... 387s Unpacking libgit2-1.7:armhf (1.7.2+ds-1ubuntu3) ... 387s Selecting previously unselected package libllvm18:armhf. 387s Preparing to unpack .../035-libllvm18_1%3a18.1.8-12_armhf.deb ... 387s Unpacking libllvm18:armhf (1:18.1.8-12) ... 389s Selecting previously unselected package libstd-rust-1.80:armhf. 389s Preparing to unpack .../036-libstd-rust-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_armhf.deb ... 389s Unpacking libstd-rust-1.80:armhf (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 389s Selecting previously unselected package libstd-rust-1.80-dev:armhf. 389s Preparing to unpack .../037-libstd-rust-1.80-dev_1.80.1+dfsg0ubuntu1-0ubuntu1_armhf.deb ... 389s Unpacking libstd-rust-1.80-dev:armhf (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 390s Selecting previously unselected package rustc-1.80. 390s Preparing to unpack .../038-rustc-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_armhf.deb ... 390s Unpacking rustc-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 390s Selecting previously unselected package cargo-1.80. 390s Preparing to unpack .../039-cargo-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_armhf.deb ... 390s Unpacking cargo-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 391s Selecting previously unselected package libjsoncpp25:armhf. 391s Preparing to unpack .../040-libjsoncpp25_1.9.5-6build1_armhf.deb ... 391s Unpacking libjsoncpp25:armhf (1.9.5-6build1) ... 391s Selecting previously unselected package librhash0:armhf. 391s Preparing to unpack .../041-librhash0_1.4.3-3build1_armhf.deb ... 391s Unpacking librhash0:armhf (1.4.3-3build1) ... 391s Selecting previously unselected package cmake-data. 391s Preparing to unpack .../042-cmake-data_3.30.3-1_all.deb ... 391s Unpacking cmake-data (3.30.3-1) ... 392s Selecting previously unselected package cmake. 392s Preparing to unpack .../043-cmake_3.30.3-1_armhf.deb ... 392s Unpacking cmake (3.30.3-1) ... 392s Selecting previously unselected package libdebhelper-perl. 392s Preparing to unpack .../044-libdebhelper-perl_13.20ubuntu1_all.deb ... 392s Unpacking libdebhelper-perl (13.20ubuntu1) ... 392s Selecting previously unselected package libtool. 392s Preparing to unpack .../045-libtool_2.4.7-8_all.deb ... 392s Unpacking libtool (2.4.7-8) ... 392s Selecting previously unselected package dh-autoreconf. 392s Preparing to unpack .../046-dh-autoreconf_20_all.deb ... 392s Unpacking dh-autoreconf (20) ... 392s Selecting previously unselected package libarchive-zip-perl. 392s Preparing to unpack .../047-libarchive-zip-perl_1.68-1_all.deb ... 392s Unpacking libarchive-zip-perl (1.68-1) ... 392s Selecting previously unselected package libfile-stripnondeterminism-perl. 392s Preparing to unpack .../048-libfile-stripnondeterminism-perl_1.14.0-1_all.deb ... 392s Unpacking libfile-stripnondeterminism-perl (1.14.0-1) ... 392s Selecting previously unselected package dh-strip-nondeterminism. 392s Preparing to unpack .../049-dh-strip-nondeterminism_1.14.0-1_all.deb ... 392s Unpacking dh-strip-nondeterminism (1.14.0-1) ... 392s Selecting previously unselected package debugedit. 392s Preparing to unpack .../050-debugedit_1%3a5.1-1_armhf.deb ... 392s Unpacking debugedit (1:5.1-1) ... 392s Selecting previously unselected package dwz. 392s Preparing to unpack .../051-dwz_0.15-1build6_armhf.deb ... 392s Unpacking dwz (0.15-1build6) ... 392s Selecting previously unselected package gettext. 392s Preparing to unpack .../052-gettext_0.22.5-2_armhf.deb ... 392s Unpacking gettext (0.22.5-2) ... 392s Selecting previously unselected package intltool-debian. 392s Preparing to unpack .../053-intltool-debian_0.35.0+20060710.6_all.deb ... 392s Unpacking intltool-debian (0.35.0+20060710.6) ... 392s Selecting previously unselected package po-debconf. 392s Preparing to unpack .../054-po-debconf_1.0.21+nmu1_all.deb ... 392s Unpacking po-debconf (1.0.21+nmu1) ... 393s Selecting previously unselected package debhelper. 393s Preparing to unpack .../055-debhelper_13.20ubuntu1_all.deb ... 393s Unpacking debhelper (13.20ubuntu1) ... 393s Selecting previously unselected package dh-python. 393s Preparing to unpack .../056-dh-python_6.20241024_all.deb ... 393s Unpacking dh-python (6.20241024) ... 393s Selecting previously unselected package fonts-dejavu-mono. 393s Preparing to unpack .../057-fonts-dejavu-mono_2.37-8_all.deb ... 393s Unpacking fonts-dejavu-mono (2.37-8) ... 393s Selecting previously unselected package fonts-dejavu-core. 393s Preparing to unpack .../058-fonts-dejavu-core_2.37-8_all.deb ... 393s Unpacking fonts-dejavu-core (2.37-8) ... 393s Selecting previously unselected package fontconfig-config. 393s Preparing to unpack .../059-fontconfig-config_2.15.0-1.1ubuntu2_armhf.deb ... 393s Unpacking fontconfig-config (2.15.0-1.1ubuntu2) ... 393s Selecting previously unselected package libbrotli-dev:armhf. 393s Preparing to unpack .../060-libbrotli-dev_1.1.0-2build3_armhf.deb ... 393s Unpacking libbrotli-dev:armhf (1.1.0-2build3) ... 393s Selecting previously unselected package libbz2-dev:armhf. 393s Preparing to unpack .../061-libbz2-dev_1.0.8-6_armhf.deb ... 393s Unpacking libbz2-dev:armhf (1.0.8-6) ... 393s Selecting previously unselected package libexpat1-dev:armhf. 393s Preparing to unpack .../062-libexpat1-dev_2.6.4-1_armhf.deb ... 393s Unpacking libexpat1-dev:armhf (2.6.4-1) ... 393s Selecting previously unselected package libfreetype6:armhf. 393s Preparing to unpack .../063-libfreetype6_2.13.3+dfsg-1_armhf.deb ... 393s Unpacking libfreetype6:armhf (2.13.3+dfsg-1) ... 394s Selecting previously unselected package libfontconfig1:armhf. 394s Preparing to unpack .../064-libfontconfig1_2.15.0-1.1ubuntu2_armhf.deb ... 394s Unpacking libfontconfig1:armhf (2.15.0-1.1ubuntu2) ... 394s Selecting previously unselected package zlib1g-dev:armhf. 394s Preparing to unpack .../065-zlib1g-dev_1%3a1.3.dfsg+really1.3.1-1ubuntu1_armhf.deb ... 394s Unpacking zlib1g-dev:armhf (1:1.3.dfsg+really1.3.1-1ubuntu1) ... 394s Selecting previously unselected package libpng-dev:armhf. 394s Preparing to unpack .../066-libpng-dev_1.6.44-2_armhf.deb ... 394s Unpacking libpng-dev:armhf (1.6.44-2) ... 394s Selecting previously unselected package libfreetype-dev:armhf. 394s Preparing to unpack .../067-libfreetype-dev_2.13.3+dfsg-1_armhf.deb ... 394s Unpacking libfreetype-dev:armhf (2.13.3+dfsg-1) ... 394s Selecting previously unselected package uuid-dev:armhf. 394s Preparing to unpack .../068-uuid-dev_2.40.2-1ubuntu1_armhf.deb ... 394s Unpacking uuid-dev:armhf (2.40.2-1ubuntu1) ... 394s Selecting previously unselected package libpkgconf3:armhf. 394s Preparing to unpack .../069-libpkgconf3_1.8.1-4_armhf.deb ... 394s Unpacking libpkgconf3:armhf (1.8.1-4) ... 394s Selecting previously unselected package pkgconf-bin. 394s Preparing to unpack .../070-pkgconf-bin_1.8.1-4_armhf.deb ... 394s Unpacking pkgconf-bin (1.8.1-4) ... 394s Selecting previously unselected package pkgconf:armhf. 394s Preparing to unpack .../071-pkgconf_1.8.1-4_armhf.deb ... 394s Unpacking pkgconf:armhf (1.8.1-4) ... 394s Selecting previously unselected package libfontconfig-dev:armhf. 394s Preparing to unpack .../072-libfontconfig-dev_2.15.0-1.1ubuntu2_armhf.deb ... 394s Unpacking libfontconfig-dev:armhf (2.15.0-1.1ubuntu2) ... 394s Selecting previously unselected package libllvm19:armhf. 394s Preparing to unpack .../073-libllvm19_1%3a19.1.2-1ubuntu1_armhf.deb ... 394s Unpacking libllvm19:armhf (1:19.1.2-1ubuntu1) ... 395s Selecting previously unselected package libpython3.12t64:armhf. 395s Preparing to unpack .../074-libpython3.12t64_3.12.7-3_armhf.deb ... 395s Unpacking libpython3.12t64:armhf (3.12.7-3) ... 395s Selecting previously unselected package libpython3.12-dev:armhf. 395s Preparing to unpack .../075-libpython3.12-dev_3.12.7-3_armhf.deb ... 395s Unpacking libpython3.12-dev:armhf (3.12.7-3) ... 396s Selecting previously unselected package libpython3-dev:armhf. 396s Preparing to unpack .../076-libpython3-dev_3.12.7-1_armhf.deb ... 396s Unpacking libpython3-dev:armhf (3.12.7-1) ... 396s Selecting previously unselected package libpython3.13-stdlib:armhf. 396s Preparing to unpack .../077-libpython3.13-stdlib_3.13.0-2_armhf.deb ... 396s Unpacking libpython3.13-stdlib:armhf (3.13.0-2) ... 396s Selecting previously unselected package libpython3.13:armhf. 396s Preparing to unpack .../078-libpython3.13_3.13.0-2_armhf.deb ... 396s Unpacking libpython3.13:armhf (3.13.0-2) ... 396s Selecting previously unselected package libpython3.13-dev:armhf. 396s Preparing to unpack .../079-libpython3.13-dev_3.13.0-2_armhf.deb ... 396s Unpacking libpython3.13-dev:armhf (3.13.0-2) ... 396s Selecting previously unselected package libpython3-all-dev:armhf. 396s Preparing to unpack .../080-libpython3-all-dev_3.12.7-1_armhf.deb ... 396s Unpacking libpython3-all-dev:armhf (3.12.7-1) ... 396s Selecting previously unselected package librust-ab-glyph-rasterizer-dev:armhf. 396s Preparing to unpack .../081-librust-ab-glyph-rasterizer-dev_0.1.7-1_armhf.deb ... 396s Unpacking librust-ab-glyph-rasterizer-dev:armhf (0.1.7-1) ... 396s Selecting previously unselected package librust-libm-dev:armhf. 396s Preparing to unpack .../082-librust-libm-dev_0.2.8-1_armhf.deb ... 396s Unpacking librust-libm-dev:armhf (0.2.8-1) ... 396s Selecting previously unselected package librust-ab-glyph-rasterizer+libm-dev:armhf. 396s Preparing to unpack .../083-librust-ab-glyph-rasterizer+libm-dev_0.1.7-1_armhf.deb ... 396s Unpacking librust-ab-glyph-rasterizer+libm-dev:armhf (0.1.7-1) ... 396s Selecting previously unselected package librust-core-maths-dev:armhf. 396s Preparing to unpack .../084-librust-core-maths-dev_0.1.0-2_armhf.deb ... 396s Unpacking librust-core-maths-dev:armhf (0.1.0-2) ... 396s Selecting previously unselected package librust-ttf-parser-dev:armhf. 396s Preparing to unpack .../085-librust-ttf-parser-dev_0.24.1-1_armhf.deb ... 396s Unpacking librust-ttf-parser-dev:armhf (0.24.1-1) ... 397s Selecting previously unselected package librust-owned-ttf-parser-dev:armhf. 397s Preparing to unpack .../086-librust-owned-ttf-parser-dev_0.24.0-1_armhf.deb ... 397s Unpacking librust-owned-ttf-parser-dev:armhf (0.24.0-1) ... 397s Selecting previously unselected package librust-ab-glyph-dev:armhf. 397s Preparing to unpack .../087-librust-ab-glyph-dev_0.2.28-1_armhf.deb ... 397s Unpacking librust-ab-glyph-dev:armhf (0.2.28-1) ... 397s Selecting previously unselected package librust-cfg-if-dev:armhf. 397s Preparing to unpack .../088-librust-cfg-if-dev_1.0.0-1_armhf.deb ... 397s Unpacking librust-cfg-if-dev:armhf (1.0.0-1) ... 397s Selecting previously unselected package librust-cpp-demangle-dev:armhf. 397s Preparing to unpack .../089-librust-cpp-demangle-dev_0.4.0-1_armhf.deb ... 397s Unpacking librust-cpp-demangle-dev:armhf (0.4.0-1) ... 397s Selecting previously unselected package librust-fallible-iterator-dev:armhf. 397s Preparing to unpack .../090-librust-fallible-iterator-dev_0.3.0-2_armhf.deb ... 397s Unpacking librust-fallible-iterator-dev:armhf (0.3.0-2) ... 397s Selecting previously unselected package librust-unicode-ident-dev:armhf. 397s Preparing to unpack .../091-librust-unicode-ident-dev_1.0.13-1_armhf.deb ... 397s Unpacking librust-unicode-ident-dev:armhf (1.0.13-1) ... 397s Selecting previously unselected package librust-proc-macro2-dev:armhf. 397s Preparing to unpack .../092-librust-proc-macro2-dev_1.0.86-1_armhf.deb ... 397s Unpacking librust-proc-macro2-dev:armhf (1.0.86-1) ... 397s Selecting previously unselected package librust-quote-dev:armhf. 397s Preparing to unpack .../093-librust-quote-dev_1.0.37-1_armhf.deb ... 397s Unpacking librust-quote-dev:armhf (1.0.37-1) ... 397s Selecting previously unselected package librust-syn-dev:armhf. 397s Preparing to unpack .../094-librust-syn-dev_2.0.85-1_armhf.deb ... 397s Unpacking librust-syn-dev:armhf (2.0.85-1) ... 397s Selecting previously unselected package librust-derive-arbitrary-dev:armhf. 397s Preparing to unpack .../095-librust-derive-arbitrary-dev_1.3.2-1_armhf.deb ... 397s Unpacking librust-derive-arbitrary-dev:armhf (1.3.2-1) ... 397s Selecting previously unselected package librust-arbitrary-dev:armhf. 397s Preparing to unpack .../096-librust-arbitrary-dev_1.3.2-1_armhf.deb ... 397s Unpacking librust-arbitrary-dev:armhf (1.3.2-1) ... 397s Selecting previously unselected package librust-equivalent-dev:armhf. 397s Preparing to unpack .../097-librust-equivalent-dev_1.0.1-1_armhf.deb ... 397s Unpacking librust-equivalent-dev:armhf (1.0.1-1) ... 397s Selecting previously unselected package librust-critical-section-dev:armhf. 397s Preparing to unpack .../098-librust-critical-section-dev_1.1.3-1_armhf.deb ... 397s Unpacking librust-critical-section-dev:armhf (1.1.3-1) ... 397s Selecting previously unselected package librust-serde-derive-dev:armhf. 397s Preparing to unpack .../099-librust-serde-derive-dev_1.0.210-1_armhf.deb ... 397s Unpacking librust-serde-derive-dev:armhf (1.0.210-1) ... 397s Selecting previously unselected package librust-serde-dev:armhf. 397s Preparing to unpack .../100-librust-serde-dev_1.0.210-2_armhf.deb ... 397s Unpacking librust-serde-dev:armhf (1.0.210-2) ... 397s Selecting previously unselected package librust-portable-atomic-dev:armhf. 397s Preparing to unpack .../101-librust-portable-atomic-dev_1.9.0-4_armhf.deb ... 397s Unpacking librust-portable-atomic-dev:armhf (1.9.0-4) ... 397s Selecting previously unselected package librust-rustc-std-workspace-core-dev:armhf. 398s Preparing to unpack .../102-librust-rustc-std-workspace-core-dev_1.0.0-1_armhf.deb ... 398s Unpacking librust-rustc-std-workspace-core-dev:armhf (1.0.0-1) ... 398s Selecting previously unselected package librust-libc-dev:armhf. 398s Preparing to unpack .../103-librust-libc-dev_0.2.161-1_armhf.deb ... 398s Unpacking librust-libc-dev:armhf (0.2.161-1) ... 398s Selecting previously unselected package librust-getrandom-dev:armhf. 398s Preparing to unpack .../104-librust-getrandom-dev_0.2.12-1_armhf.deb ... 398s Unpacking librust-getrandom-dev:armhf (0.2.12-1) ... 398s Selecting previously unselected package librust-smallvec-dev:armhf. 398s Preparing to unpack .../105-librust-smallvec-dev_1.13.2-1_armhf.deb ... 398s Unpacking librust-smallvec-dev:armhf (1.13.2-1) ... 398s Selecting previously unselected package librust-parking-lot-core-dev:armhf. 398s Preparing to unpack .../106-librust-parking-lot-core-dev_0.9.10-1_armhf.deb ... 398s Unpacking librust-parking-lot-core-dev:armhf (0.9.10-1) ... 398s Selecting previously unselected package librust-once-cell-dev:armhf. 398s Preparing to unpack .../107-librust-once-cell-dev_1.20.2-1_armhf.deb ... 398s Unpacking librust-once-cell-dev:armhf (1.20.2-1) ... 398s Selecting previously unselected package librust-crunchy-dev:armhf. 398s Preparing to unpack .../108-librust-crunchy-dev_0.2.2-1_armhf.deb ... 398s Unpacking librust-crunchy-dev:armhf (0.2.2-1) ... 398s Selecting previously unselected package librust-tiny-keccak-dev:armhf. 398s Preparing to unpack .../109-librust-tiny-keccak-dev_2.0.2-1_armhf.deb ... 398s Unpacking librust-tiny-keccak-dev:armhf (2.0.2-1) ... 398s Selecting previously unselected package librust-const-random-macro-dev:armhf. 398s Preparing to unpack .../110-librust-const-random-macro-dev_0.1.16-2_armhf.deb ... 398s Unpacking librust-const-random-macro-dev:armhf (0.1.16-2) ... 398s Selecting previously unselected package librust-const-random-dev:armhf. 398s Preparing to unpack .../111-librust-const-random-dev_0.1.17-2_armhf.deb ... 398s Unpacking librust-const-random-dev:armhf (0.1.17-2) ... 398s Selecting previously unselected package librust-version-check-dev:armhf. 398s Preparing to unpack .../112-librust-version-check-dev_0.9.5-1_armhf.deb ... 398s Unpacking librust-version-check-dev:armhf (0.9.5-1) ... 398s Selecting previously unselected package librust-byteorder-dev:armhf. 398s Preparing to unpack .../113-librust-byteorder-dev_1.5.0-1_armhf.deb ... 398s Unpacking librust-byteorder-dev:armhf (1.5.0-1) ... 398s Selecting previously unselected package librust-zerocopy-derive-dev:armhf. 398s Preparing to unpack .../114-librust-zerocopy-derive-dev_0.7.32-2_armhf.deb ... 398s Unpacking librust-zerocopy-derive-dev:armhf (0.7.32-2) ... 398s Selecting previously unselected package librust-zerocopy-dev:armhf. 398s Preparing to unpack .../115-librust-zerocopy-dev_0.7.32-1_armhf.deb ... 398s Unpacking librust-zerocopy-dev:armhf (0.7.32-1) ... 398s Selecting previously unselected package librust-ahash-dev. 398s Preparing to unpack .../116-librust-ahash-dev_0.8.11-8_all.deb ... 398s Unpacking librust-ahash-dev (0.8.11-8) ... 398s Selecting previously unselected package librust-allocator-api2-dev:armhf. 398s Preparing to unpack .../117-librust-allocator-api2-dev_0.2.16-1_armhf.deb ... 398s Unpacking librust-allocator-api2-dev:armhf (0.2.16-1) ... 399s Selecting previously unselected package librust-compiler-builtins-dev:armhf. 399s Preparing to unpack .../118-librust-compiler-builtins-dev_0.1.101-1_armhf.deb ... 399s Unpacking librust-compiler-builtins-dev:armhf (0.1.101-1) ... 399s Selecting previously unselected package librust-either-dev:armhf. 399s Preparing to unpack .../119-librust-either-dev_1.13.0-1_armhf.deb ... 399s Unpacking librust-either-dev:armhf (1.13.0-1) ... 399s Selecting previously unselected package librust-crossbeam-utils-dev:armhf. 399s Preparing to unpack .../120-librust-crossbeam-utils-dev_0.8.19-1_armhf.deb ... 399s Unpacking librust-crossbeam-utils-dev:armhf (0.8.19-1) ... 399s Selecting previously unselected package librust-crossbeam-epoch-dev:armhf. 399s Preparing to unpack .../121-librust-crossbeam-epoch-dev_0.9.18-1_armhf.deb ... 399s Unpacking librust-crossbeam-epoch-dev:armhf (0.9.18-1) ... 399s Selecting previously unselected package librust-crossbeam-epoch+std-dev:armhf. 399s Preparing to unpack .../122-librust-crossbeam-epoch+std-dev_0.9.18-1_armhf.deb ... 399s Unpacking librust-crossbeam-epoch+std-dev:armhf (0.9.18-1) ... 399s Selecting previously unselected package librust-crossbeam-deque-dev:armhf. 399s Preparing to unpack .../123-librust-crossbeam-deque-dev_0.8.5-1_armhf.deb ... 399s Unpacking librust-crossbeam-deque-dev:armhf (0.8.5-1) ... 399s Selecting previously unselected package librust-rayon-core-dev:armhf. 399s Preparing to unpack .../124-librust-rayon-core-dev_1.12.1-1_armhf.deb ... 399s Unpacking librust-rayon-core-dev:armhf (1.12.1-1) ... 399s Selecting previously unselected package librust-rayon-dev:armhf. 399s Preparing to unpack .../125-librust-rayon-dev_1.10.0-1_armhf.deb ... 399s Unpacking librust-rayon-dev:armhf (1.10.0-1) ... 399s Selecting previously unselected package librust-hashbrown-dev:armhf. 399s Preparing to unpack .../126-librust-hashbrown-dev_0.14.5-5_armhf.deb ... 399s Unpacking librust-hashbrown-dev:armhf (0.14.5-5) ... 399s Selecting previously unselected package librust-indexmap-dev:armhf. 399s Preparing to unpack .../127-librust-indexmap-dev_2.2.6-1_armhf.deb ... 399s Unpacking librust-indexmap-dev:armhf (2.2.6-1) ... 399s Selecting previously unselected package librust-stable-deref-trait-dev:armhf. 399s Preparing to unpack .../128-librust-stable-deref-trait-dev_1.2.0-1_armhf.deb ... 399s Unpacking librust-stable-deref-trait-dev:armhf (1.2.0-1) ... 399s Selecting previously unselected package librust-gimli-dev:armhf. 400s Preparing to unpack .../129-librust-gimli-dev_0.28.1-2_armhf.deb ... 400s Unpacking librust-gimli-dev:armhf (0.28.1-2) ... 400s Selecting previously unselected package librust-memmap2-dev:armhf. 400s Preparing to unpack .../130-librust-memmap2-dev_0.9.3-1_armhf.deb ... 400s Unpacking librust-memmap2-dev:armhf (0.9.3-1) ... 400s Selecting previously unselected package librust-crc32fast-dev:armhf. 400s Preparing to unpack .../131-librust-crc32fast-dev_1.4.2-1_armhf.deb ... 400s Unpacking librust-crc32fast-dev:armhf (1.4.2-1) ... 400s Selecting previously unselected package pkg-config:armhf. 400s Preparing to unpack .../132-pkg-config_1.8.1-4_armhf.deb ... 400s Unpacking pkg-config:armhf (1.8.1-4) ... 400s Selecting previously unselected package librust-pkg-config-dev:armhf. 400s Preparing to unpack .../133-librust-pkg-config-dev_0.3.27-1_armhf.deb ... 400s Unpacking librust-pkg-config-dev:armhf (0.3.27-1) ... 400s Selecting previously unselected package librust-libz-sys-dev:armhf. 400s Preparing to unpack .../134-librust-libz-sys-dev_1.1.20-1_armhf.deb ... 400s Unpacking librust-libz-sys-dev:armhf (1.1.20-1) ... 400s Selecting previously unselected package librust-adler-dev:armhf. 400s Preparing to unpack .../135-librust-adler-dev_1.0.2-2_armhf.deb ... 400s Unpacking librust-adler-dev:armhf (1.0.2-2) ... 400s Selecting previously unselected package librust-miniz-oxide-dev:armhf. 400s Preparing to unpack .../136-librust-miniz-oxide-dev_0.7.1-1_armhf.deb ... 400s Unpacking librust-miniz-oxide-dev:armhf (0.7.1-1) ... 400s Selecting previously unselected package librust-flate2-dev:armhf. 400s Preparing to unpack .../137-librust-flate2-dev_1.0.34-1_armhf.deb ... 400s Unpacking librust-flate2-dev:armhf (1.0.34-1) ... 400s Selecting previously unselected package librust-sval-derive-dev:armhf. 400s Preparing to unpack .../138-librust-sval-derive-dev_2.6.1-2_armhf.deb ... 400s Unpacking librust-sval-derive-dev:armhf (2.6.1-2) ... 400s Selecting previously unselected package librust-sval-dev:armhf. 400s Preparing to unpack .../139-librust-sval-dev_2.6.1-2_armhf.deb ... 400s Unpacking librust-sval-dev:armhf (2.6.1-2) ... 400s Selecting previously unselected package librust-sval-ref-dev:armhf. 400s Preparing to unpack .../140-librust-sval-ref-dev_2.6.1-1_armhf.deb ... 400s Unpacking librust-sval-ref-dev:armhf (2.6.1-1) ... 400s Selecting previously unselected package librust-erased-serde-dev:armhf. 400s Preparing to unpack .../141-librust-erased-serde-dev_0.3.31-1_armhf.deb ... 400s Unpacking librust-erased-serde-dev:armhf (0.3.31-1) ... 400s Selecting previously unselected package librust-serde-fmt-dev. 400s Preparing to unpack .../142-librust-serde-fmt-dev_1.0.3-3_all.deb ... 400s Unpacking librust-serde-fmt-dev (1.0.3-3) ... 400s Selecting previously unselected package librust-syn-1-dev:armhf. 400s Preparing to unpack .../143-librust-syn-1-dev_1.0.109-3_armhf.deb ... 400s Unpacking librust-syn-1-dev:armhf (1.0.109-3) ... 400s Selecting previously unselected package librust-no-panic-dev:armhf. 400s Preparing to unpack .../144-librust-no-panic-dev_0.1.13-1_armhf.deb ... 400s Unpacking librust-no-panic-dev:armhf (0.1.13-1) ... 400s Selecting previously unselected package librust-itoa-dev:armhf. 400s Preparing to unpack .../145-librust-itoa-dev_1.0.9-1_armhf.deb ... 400s Unpacking librust-itoa-dev:armhf (1.0.9-1) ... 400s Selecting previously unselected package librust-ryu-dev:armhf. 401s Preparing to unpack .../146-librust-ryu-dev_1.0.15-1_armhf.deb ... 401s Unpacking librust-ryu-dev:armhf (1.0.15-1) ... 401s Selecting previously unselected package librust-serde-json-dev:armhf. 401s Preparing to unpack .../147-librust-serde-json-dev_1.0.128-1_armhf.deb ... 401s Unpacking librust-serde-json-dev:armhf (1.0.128-1) ... 401s Selecting previously unselected package librust-serde-test-dev:armhf. 401s Preparing to unpack .../148-librust-serde-test-dev_1.0.171-1_armhf.deb ... 401s Unpacking librust-serde-test-dev:armhf (1.0.171-1) ... 401s Selecting previously unselected package librust-value-bag-serde1-dev:armhf. 401s Preparing to unpack .../149-librust-value-bag-serde1-dev_1.9.0-1_armhf.deb ... 401s Unpacking librust-value-bag-serde1-dev:armhf (1.9.0-1) ... 401s Selecting previously unselected package librust-sval-buffer-dev:armhf. 401s Preparing to unpack .../150-librust-sval-buffer-dev_2.6.1-1_armhf.deb ... 401s Unpacking librust-sval-buffer-dev:armhf (2.6.1-1) ... 401s Selecting previously unselected package librust-sval-dynamic-dev:armhf. 401s Preparing to unpack .../151-librust-sval-dynamic-dev_2.6.1-1_armhf.deb ... 401s Unpacking librust-sval-dynamic-dev:armhf (2.6.1-1) ... 401s Selecting previously unselected package librust-sval-fmt-dev:armhf. 401s Preparing to unpack .../152-librust-sval-fmt-dev_2.6.1-1_armhf.deb ... 401s Unpacking librust-sval-fmt-dev:armhf (2.6.1-1) ... 401s Selecting previously unselected package librust-sval-serde-dev:armhf. 401s Preparing to unpack .../153-librust-sval-serde-dev_2.6.1-1_armhf.deb ... 401s Unpacking librust-sval-serde-dev:armhf (2.6.1-1) ... 401s Selecting previously unselected package librust-value-bag-sval2-dev:armhf. 401s Preparing to unpack .../154-librust-value-bag-sval2-dev_1.9.0-1_armhf.deb ... 401s Unpacking librust-value-bag-sval2-dev:armhf (1.9.0-1) ... 401s Selecting previously unselected package librust-value-bag-dev:armhf. 401s Preparing to unpack .../155-librust-value-bag-dev_1.9.0-1_armhf.deb ... 401s Unpacking librust-value-bag-dev:armhf (1.9.0-1) ... 401s Selecting previously unselected package librust-log-dev:armhf. 401s Preparing to unpack .../156-librust-log-dev_0.4.22-1_armhf.deb ... 401s Unpacking librust-log-dev:armhf (0.4.22-1) ... 401s Selecting previously unselected package librust-memchr-dev:armhf. 401s Preparing to unpack .../157-librust-memchr-dev_2.7.4-1_armhf.deb ... 401s Unpacking librust-memchr-dev:armhf (2.7.4-1) ... 401s Selecting previously unselected package librust-ppv-lite86-dev:armhf. 401s Preparing to unpack .../158-librust-ppv-lite86-dev_0.2.16-1_armhf.deb ... 401s Unpacking librust-ppv-lite86-dev:armhf (0.2.16-1) ... 401s Selecting previously unselected package librust-rand-core-dev:armhf. 401s Preparing to unpack .../159-librust-rand-core-dev_0.6.4-2_armhf.deb ... 401s Unpacking librust-rand-core-dev:armhf (0.6.4-2) ... 401s Selecting previously unselected package librust-rand-chacha-dev:armhf. 401s Preparing to unpack .../160-librust-rand-chacha-dev_0.3.1-2_armhf.deb ... 401s Unpacking librust-rand-chacha-dev:armhf (0.3.1-2) ... 401s Selecting previously unselected package librust-rand-core+getrandom-dev:armhf. 401s Preparing to unpack .../161-librust-rand-core+getrandom-dev_0.6.4-2_armhf.deb ... 401s Unpacking librust-rand-core+getrandom-dev:armhf (0.6.4-2) ... 401s Selecting previously unselected package librust-rand-core+serde-dev:armhf. 401s Preparing to unpack .../162-librust-rand-core+serde-dev_0.6.4-2_armhf.deb ... 401s Unpacking librust-rand-core+serde-dev:armhf (0.6.4-2) ... 402s Selecting previously unselected package librust-rand-core+std-dev:armhf. 402s Preparing to unpack .../163-librust-rand-core+std-dev_0.6.4-2_armhf.deb ... 402s Unpacking librust-rand-core+std-dev:armhf (0.6.4-2) ... 402s Selecting previously unselected package librust-rand-dev:armhf. 402s Preparing to unpack .../164-librust-rand-dev_0.8.5-1_armhf.deb ... 402s Unpacking librust-rand-dev:armhf (0.8.5-1) ... 402s Selecting previously unselected package librust-unicode-segmentation-dev:armhf. 402s Preparing to unpack .../165-librust-unicode-segmentation-dev_1.11.0-1_armhf.deb ... 402s Unpacking librust-unicode-segmentation-dev:armhf (1.11.0-1) ... 402s Selecting previously unselected package librust-convert-case-dev:armhf. 402s Preparing to unpack .../166-librust-convert-case-dev_0.6.0-2_armhf.deb ... 402s Unpacking librust-convert-case-dev:armhf (0.6.0-2) ... 402s Selecting previously unselected package librust-semver-dev:armhf. 402s Preparing to unpack .../167-librust-semver-dev_1.0.23-1_armhf.deb ... 402s Unpacking librust-semver-dev:armhf (1.0.23-1) ... 402s Selecting previously unselected package librust-rustc-version-dev:armhf. 402s Preparing to unpack .../168-librust-rustc-version-dev_0.4.0-1_armhf.deb ... 402s Unpacking librust-rustc-version-dev:armhf (0.4.0-1) ... 402s Selecting previously unselected package librust-derive-more-0.99-dev:armhf. 402s Preparing to unpack .../169-librust-derive-more-0.99-dev_0.99.18-2_armhf.deb ... 402s Unpacking librust-derive-more-0.99-dev:armhf (0.99.18-2) ... 402s Selecting previously unselected package librust-cfg-if-0.1-dev:armhf. 402s Preparing to unpack .../170-librust-cfg-if-0.1-dev_0.1.10-3_armhf.deb ... 402s Unpacking librust-cfg-if-0.1-dev:armhf (0.1.10-3) ... 402s Selecting previously unselected package librust-blobby-dev:armhf. 402s Preparing to unpack .../171-librust-blobby-dev_0.3.1-1_armhf.deb ... 402s Unpacking librust-blobby-dev:armhf (0.3.1-1) ... 402s Selecting previously unselected package librust-typenum-dev:armhf. 402s Preparing to unpack .../172-librust-typenum-dev_1.17.0-2_armhf.deb ... 402s Unpacking librust-typenum-dev:armhf (1.17.0-2) ... 402s Selecting previously unselected package librust-zeroize-derive-dev:armhf. 402s Preparing to unpack .../173-librust-zeroize-derive-dev_1.4.2-1_armhf.deb ... 402s Unpacking librust-zeroize-derive-dev:armhf (1.4.2-1) ... 402s Selecting previously unselected package librust-zeroize-dev:armhf. 402s Preparing to unpack .../174-librust-zeroize-dev_1.8.1-1_armhf.deb ... 402s Unpacking librust-zeroize-dev:armhf (1.8.1-1) ... 402s Selecting previously unselected package librust-generic-array-dev:armhf. 402s Preparing to unpack .../175-librust-generic-array-dev_0.14.7-1_armhf.deb ... 402s Unpacking librust-generic-array-dev:armhf (0.14.7-1) ... 402s Selecting previously unselected package librust-block-buffer-dev:armhf. 402s Preparing to unpack .../176-librust-block-buffer-dev_0.10.2-2_armhf.deb ... 402s Unpacking librust-block-buffer-dev:armhf (0.10.2-2) ... 402s Selecting previously unselected package librust-const-oid-dev:armhf. 402s Preparing to unpack .../177-librust-const-oid-dev_0.9.3-1_armhf.deb ... 402s Unpacking librust-const-oid-dev:armhf (0.9.3-1) ... 402s Selecting previously unselected package librust-crypto-common-dev:armhf. 402s Preparing to unpack .../178-librust-crypto-common-dev_0.1.6-1_armhf.deb ... 402s Unpacking librust-crypto-common-dev:armhf (0.1.6-1) ... 402s Selecting previously unselected package librust-subtle-dev:armhf. 402s Preparing to unpack .../179-librust-subtle-dev_2.6.1-1_armhf.deb ... 402s Unpacking librust-subtle-dev:armhf (2.6.1-1) ... 403s Selecting previously unselected package librust-digest-dev:armhf. 403s Preparing to unpack .../180-librust-digest-dev_0.10.7-2_armhf.deb ... 403s Unpacking librust-digest-dev:armhf (0.10.7-2) ... 403s Selecting previously unselected package librust-static-assertions-dev:armhf. 403s Preparing to unpack .../181-librust-static-assertions-dev_1.1.0-1_armhf.deb ... 403s Unpacking librust-static-assertions-dev:armhf (1.1.0-1) ... 403s Selecting previously unselected package librust-twox-hash-dev:armhf. 403s Preparing to unpack .../182-librust-twox-hash-dev_1.6.3-1_armhf.deb ... 403s Unpacking librust-twox-hash-dev:armhf (1.6.3-1) ... 403s Selecting previously unselected package librust-ruzstd-dev:armhf. 403s Preparing to unpack .../183-librust-ruzstd-dev_0.5.0-1_armhf.deb ... 403s Unpacking librust-ruzstd-dev:armhf (0.5.0-1) ... 403s Selecting previously unselected package librust-object-dev:armhf. 403s Preparing to unpack .../184-librust-object-dev_0.32.2-1_armhf.deb ... 403s Unpacking librust-object-dev:armhf (0.32.2-1) ... 403s Selecting previously unselected package librust-rustc-demangle-dev:armhf. 403s Preparing to unpack .../185-librust-rustc-demangle-dev_0.1.21-1_armhf.deb ... 403s Unpacking librust-rustc-demangle-dev:armhf (0.1.21-1) ... 403s Selecting previously unselected package librust-addr2line-dev:armhf. 403s Preparing to unpack .../186-librust-addr2line-dev_0.21.0-2_armhf.deb ... 403s Unpacking librust-addr2line-dev:armhf (0.21.0-2) ... 403s Selecting previously unselected package librust-aho-corasick-dev:armhf. 403s Preparing to unpack .../187-librust-aho-corasick-dev_1.1.3-1_armhf.deb ... 403s Unpacking librust-aho-corasick-dev:armhf (1.1.3-1) ... 403s Selecting previously unselected package librust-bitflags-1-dev:armhf. 403s Preparing to unpack .../188-librust-bitflags-1-dev_1.3.2-5_armhf.deb ... 403s Unpacking librust-bitflags-1-dev:armhf (1.3.2-5) ... 403s Selecting previously unselected package librust-anes-dev:armhf. 403s Preparing to unpack .../189-librust-anes-dev_0.1.6-1_armhf.deb ... 403s Unpacking librust-anes-dev:armhf (0.1.6-1) ... 403s Selecting previously unselected package librust-anstyle-dev:armhf. 403s Preparing to unpack .../190-librust-anstyle-dev_1.0.8-1_armhf.deb ... 403s Unpacking librust-anstyle-dev:armhf (1.0.8-1) ... 403s Selecting previously unselected package librust-arrayvec-dev:armhf. 403s Preparing to unpack .../191-librust-arrayvec-dev_0.7.4-2_armhf.deb ... 403s Unpacking librust-arrayvec-dev:armhf (0.7.4-2) ... 403s Selecting previously unselected package librust-utf8parse-dev:armhf. 404s Preparing to unpack .../192-librust-utf8parse-dev_0.2.1-1_armhf.deb ... 404s Unpacking librust-utf8parse-dev:armhf (0.2.1-1) ... 404s Selecting previously unselected package librust-anstyle-parse-dev:armhf. 404s Preparing to unpack .../193-librust-anstyle-parse-dev_0.2.1-1_armhf.deb ... 404s Unpacking librust-anstyle-parse-dev:armhf (0.2.1-1) ... 404s Selecting previously unselected package librust-anstyle-query-dev:armhf. 404s Preparing to unpack .../194-librust-anstyle-query-dev_1.0.0-1_armhf.deb ... 404s Unpacking librust-anstyle-query-dev:armhf (1.0.0-1) ... 404s Selecting previously unselected package librust-colorchoice-dev:armhf. 404s Preparing to unpack .../195-librust-colorchoice-dev_1.0.0-1_armhf.deb ... 404s Unpacking librust-colorchoice-dev:armhf (1.0.0-1) ... 404s Selecting previously unselected package librust-anstream-dev:armhf. 404s Preparing to unpack .../196-librust-anstream-dev_0.6.15-1_armhf.deb ... 404s Unpacking librust-anstream-dev:armhf (0.6.15-1) ... 404s Selecting previously unselected package librust-jobserver-dev:armhf. 404s Preparing to unpack .../197-librust-jobserver-dev_0.1.32-1_armhf.deb ... 404s Unpacking librust-jobserver-dev:armhf (0.1.32-1) ... 404s Selecting previously unselected package librust-shlex-dev:armhf. 404s Preparing to unpack .../198-librust-shlex-dev_1.3.0-1_armhf.deb ... 404s Unpacking librust-shlex-dev:armhf (1.3.0-1) ... 404s Selecting previously unselected package librust-cc-dev:armhf. 404s Preparing to unpack .../199-librust-cc-dev_1.1.14-1_armhf.deb ... 404s Unpacking librust-cc-dev:armhf (1.1.14-1) ... 404s Selecting previously unselected package librust-backtrace-dev:armhf. 404s Preparing to unpack .../200-librust-backtrace-dev_0.3.69-2_armhf.deb ... 404s Unpacking librust-backtrace-dev:armhf (0.3.69-2) ... 404s Selecting previously unselected package librust-anyhow-dev:armhf. 404s Preparing to unpack .../201-librust-anyhow-dev_1.0.86-1_armhf.deb ... 404s Unpacking librust-anyhow-dev:armhf (1.0.86-1) ... 404s Selecting previously unselected package librust-bytecheck-derive-dev:armhf. 404s Preparing to unpack .../202-librust-bytecheck-derive-dev_0.6.12-1_armhf.deb ... 404s Unpacking librust-bytecheck-derive-dev:armhf (0.6.12-1) ... 404s Selecting previously unselected package librust-ptr-meta-derive-dev:armhf. 404s Preparing to unpack .../203-librust-ptr-meta-derive-dev_0.1.4-1_armhf.deb ... 404s Unpacking librust-ptr-meta-derive-dev:armhf (0.1.4-1) ... 404s Selecting previously unselected package librust-ptr-meta-dev:armhf. 404s Preparing to unpack .../204-librust-ptr-meta-dev_0.1.4-1_armhf.deb ... 404s Unpacking librust-ptr-meta-dev:armhf (0.1.4-1) ... 404s Selecting previously unselected package librust-simdutf8-dev:armhf. 404s Preparing to unpack .../205-librust-simdutf8-dev_0.1.4-4_armhf.deb ... 404s Unpacking librust-simdutf8-dev:armhf (0.1.4-4) ... 404s Selecting previously unselected package librust-bytemuck-derive-dev:armhf. 404s Preparing to unpack .../206-librust-bytemuck-derive-dev_1.5.0-2_armhf.deb ... 404s Unpacking librust-bytemuck-derive-dev:armhf (1.5.0-2) ... 404s Selecting previously unselected package librust-bytemuck-dev:armhf. 404s Preparing to unpack .../207-librust-bytemuck-dev_1.14.0-1_armhf.deb ... 404s Unpacking librust-bytemuck-dev:armhf (1.14.0-1) ... 405s Selecting previously unselected package librust-atomic-dev:armhf. 405s Preparing to unpack .../208-librust-atomic-dev_0.6.0-1_armhf.deb ... 405s Unpacking librust-atomic-dev:armhf (0.6.0-1) ... 405s Selecting previously unselected package librust-md5-asm-dev:armhf. 405s Preparing to unpack .../209-librust-md5-asm-dev_0.5.0-2_armhf.deb ... 405s Unpacking librust-md5-asm-dev:armhf (0.5.0-2) ... 405s Selecting previously unselected package librust-md-5-dev:armhf. 405s Preparing to unpack .../210-librust-md-5-dev_0.10.6-1_armhf.deb ... 405s Unpacking librust-md-5-dev:armhf (0.10.6-1) ... 405s Selecting previously unselected package librust-cpufeatures-dev:armhf. 405s Preparing to unpack .../211-librust-cpufeatures-dev_0.2.11-1_armhf.deb ... 405s Unpacking librust-cpufeatures-dev:armhf (0.2.11-1) ... 405s Selecting previously unselected package librust-sha1-asm-dev:armhf. 405s Preparing to unpack .../212-librust-sha1-asm-dev_0.5.1-2_armhf.deb ... 405s Unpacking librust-sha1-asm-dev:armhf (0.5.1-2) ... 405s Selecting previously unselected package librust-sha1-dev:armhf. 405s Preparing to unpack .../213-librust-sha1-dev_0.10.6-1_armhf.deb ... 405s Unpacking librust-sha1-dev:armhf (0.10.6-1) ... 405s Selecting previously unselected package librust-slog-dev:armhf. 405s Preparing to unpack .../214-librust-slog-dev_2.7.0-1_armhf.deb ... 405s Unpacking librust-slog-dev:armhf (2.7.0-1) ... 405s Selecting previously unselected package librust-uuid-dev:armhf. 406s Preparing to unpack .../215-librust-uuid-dev_1.10.0-1_armhf.deb ... 406s Unpacking librust-uuid-dev:armhf (1.10.0-1) ... 406s Selecting previously unselected package librust-bytecheck-dev:armhf. 406s Preparing to unpack .../216-librust-bytecheck-dev_0.6.12-1_armhf.deb ... 406s Unpacking librust-bytecheck-dev:armhf (0.6.12-1) ... 406s Selecting previously unselected package librust-autocfg-dev:armhf. 406s Preparing to unpack .../217-librust-autocfg-dev_1.1.0-1_armhf.deb ... 406s Unpacking librust-autocfg-dev:armhf (1.1.0-1) ... 406s Selecting previously unselected package librust-num-traits-dev:armhf. 406s Preparing to unpack .../218-librust-num-traits-dev_0.2.19-2_armhf.deb ... 406s Unpacking librust-num-traits-dev:armhf (0.2.19-2) ... 406s Selecting previously unselected package librust-funty-dev:armhf. 406s Preparing to unpack .../219-librust-funty-dev_2.0.0-1_armhf.deb ... 406s Unpacking librust-funty-dev:armhf (2.0.0-1) ... 406s Selecting previously unselected package librust-radium-dev:armhf. 406s Preparing to unpack .../220-librust-radium-dev_1.1.0-1_armhf.deb ... 406s Unpacking librust-radium-dev:armhf (1.1.0-1) ... 406s Selecting previously unselected package librust-tap-dev:armhf. 406s Preparing to unpack .../221-librust-tap-dev_1.0.1-1_armhf.deb ... 406s Unpacking librust-tap-dev:armhf (1.0.1-1) ... 406s Selecting previously unselected package librust-traitobject-dev:armhf. 406s Preparing to unpack .../222-librust-traitobject-dev_0.1.0-1_armhf.deb ... 406s Unpacking librust-traitobject-dev:armhf (0.1.0-1) ... 406s Selecting previously unselected package librust-unsafe-any-dev:armhf. 406s Preparing to unpack .../223-librust-unsafe-any-dev_0.4.2-2_armhf.deb ... 406s Unpacking librust-unsafe-any-dev:armhf (0.4.2-2) ... 406s Selecting previously unselected package librust-typemap-dev:armhf. 406s Preparing to unpack .../224-librust-typemap-dev_0.3.3-2_armhf.deb ... 406s Unpacking librust-typemap-dev:armhf (0.3.3-2) ... 406s Selecting previously unselected package librust-wyz-dev:armhf. 406s Preparing to unpack .../225-librust-wyz-dev_0.5.1-1_armhf.deb ... 406s Unpacking librust-wyz-dev:armhf (0.5.1-1) ... 406s Selecting previously unselected package librust-bitvec-dev:armhf. 407s Preparing to unpack .../226-librust-bitvec-dev_1.0.1-1_armhf.deb ... 407s Unpacking librust-bitvec-dev:armhf (1.0.1-1) ... 407s Selecting previously unselected package librust-bytes-dev:armhf. 407s Preparing to unpack .../227-librust-bytes-dev_1.8.0-1_armhf.deb ... 407s Unpacking librust-bytes-dev:armhf (1.8.0-1) ... 407s Selecting previously unselected package librust-rend-dev:armhf. 407s Preparing to unpack .../228-librust-rend-dev_0.4.0-1_armhf.deb ... 407s Unpacking librust-rend-dev:armhf (0.4.0-1) ... 407s Selecting previously unselected package librust-rkyv-derive-dev:armhf. 407s Preparing to unpack .../229-librust-rkyv-derive-dev_0.7.44-1_armhf.deb ... 407s Unpacking librust-rkyv-derive-dev:armhf (0.7.44-1) ... 407s Selecting previously unselected package librust-seahash-dev:armhf. 407s Preparing to unpack .../230-librust-seahash-dev_4.1.0-1_armhf.deb ... 407s Unpacking librust-seahash-dev:armhf (4.1.0-1) ... 407s Selecting previously unselected package librust-smol-str-dev:armhf. 407s Preparing to unpack .../231-librust-smol-str-dev_0.2.0-1_armhf.deb ... 407s Unpacking librust-smol-str-dev:armhf (0.2.0-1) ... 407s Selecting previously unselected package librust-tinyvec-dev:armhf. 407s Preparing to unpack .../232-librust-tinyvec-dev_1.6.0-2_armhf.deb ... 407s Unpacking librust-tinyvec-dev:armhf (1.6.0-2) ... 407s Selecting previously unselected package librust-tinyvec-macros-dev:armhf. 407s Preparing to unpack .../233-librust-tinyvec-macros-dev_0.1.0-1_armhf.deb ... 407s Unpacking librust-tinyvec-macros-dev:armhf (0.1.0-1) ... 407s Selecting previously unselected package librust-tinyvec+tinyvec-macros-dev:armhf. 407s Preparing to unpack .../234-librust-tinyvec+tinyvec-macros-dev_1.6.0-2_armhf.deb ... 407s Unpacking librust-tinyvec+tinyvec-macros-dev:armhf (1.6.0-2) ... 407s Selecting previously unselected package librust-rkyv-dev:armhf. 407s Preparing to unpack .../235-librust-rkyv-dev_0.7.44-1_armhf.deb ... 407s Unpacking librust-rkyv-dev:armhf (0.7.44-1) ... 407s Selecting previously unselected package librust-num-complex-dev:armhf. 407s Preparing to unpack .../236-librust-num-complex-dev_0.4.6-2_armhf.deb ... 407s Unpacking librust-num-complex-dev:armhf (0.4.6-2) ... 407s Selecting previously unselected package librust-approx-dev:armhf. 407s Preparing to unpack .../237-librust-approx-dev_0.5.1-1_armhf.deb ... 407s Unpacking librust-approx-dev:armhf (0.5.1-1) ... 407s Selecting previously unselected package librust-array-init-dev:armhf. 407s Preparing to unpack .../238-librust-array-init-dev_2.0.1-1_armhf.deb ... 407s Unpacking librust-array-init-dev:armhf (2.0.1-1) ... 407s Selecting previously unselected package librust-async-attributes-dev. 407s Preparing to unpack .../239-librust-async-attributes-dev_1.1.2-6_all.deb ... 407s Unpacking librust-async-attributes-dev (1.1.2-6) ... 408s Selecting previously unselected package librust-concurrent-queue-dev:armhf. 408s Preparing to unpack .../240-librust-concurrent-queue-dev_2.5.0-4_armhf.deb ... 408s Unpacking librust-concurrent-queue-dev:armhf (2.5.0-4) ... 408s Selecting previously unselected package librust-parking-dev:armhf. 408s Preparing to unpack .../241-librust-parking-dev_2.2.0-1_armhf.deb ... 408s Unpacking librust-parking-dev:armhf (2.2.0-1) ... 408s Selecting previously unselected package librust-pin-project-lite-dev:armhf. 408s Preparing to unpack .../242-librust-pin-project-lite-dev_0.2.13-1_armhf.deb ... 408s Unpacking librust-pin-project-lite-dev:armhf (0.2.13-1) ... 408s Selecting previously unselected package librust-event-listener-dev. 408s Preparing to unpack .../243-librust-event-listener-dev_5.3.1-8_all.deb ... 408s Unpacking librust-event-listener-dev (5.3.1-8) ... 408s Selecting previously unselected package librust-event-listener-strategy-dev:armhf. 408s Preparing to unpack .../244-librust-event-listener-strategy-dev_0.5.2-3_armhf.deb ... 408s Unpacking librust-event-listener-strategy-dev:armhf (0.5.2-3) ... 408s Selecting previously unselected package librust-futures-core-dev:armhf. 408s Preparing to unpack .../245-librust-futures-core-dev_0.3.30-1_armhf.deb ... 408s Unpacking librust-futures-core-dev:armhf (0.3.30-1) ... 408s Selecting previously unselected package librust-async-channel-dev. 408s Preparing to unpack .../246-librust-async-channel-dev_2.3.1-8_all.deb ... 408s Unpacking librust-async-channel-dev (2.3.1-8) ... 408s Selecting previously unselected package librust-async-task-dev. 408s Preparing to unpack .../247-librust-async-task-dev_4.7.1-3_all.deb ... 408s Unpacking librust-async-task-dev (4.7.1-3) ... 408s Selecting previously unselected package librust-fastrand-dev:armhf. 408s Preparing to unpack .../248-librust-fastrand-dev_2.1.1-1_armhf.deb ... 408s Unpacking librust-fastrand-dev:armhf (2.1.1-1) ... 408s Selecting previously unselected package librust-futures-io-dev:armhf. 408s Preparing to unpack .../249-librust-futures-io-dev_0.3.31-1_armhf.deb ... 408s Unpacking librust-futures-io-dev:armhf (0.3.31-1) ... 408s Selecting previously unselected package librust-futures-lite-dev:armhf. 408s Preparing to unpack .../250-librust-futures-lite-dev_2.3.0-2_armhf.deb ... 408s Unpacking librust-futures-lite-dev:armhf (2.3.0-2) ... 408s Selecting previously unselected package librust-slab-dev:armhf. 408s Preparing to unpack .../251-librust-slab-dev_0.4.9-1_armhf.deb ... 408s Unpacking librust-slab-dev:armhf (0.4.9-1) ... 408s Selecting previously unselected package librust-async-executor-dev. 408s Preparing to unpack .../252-librust-async-executor-dev_1.13.1-1_all.deb ... 408s Unpacking librust-async-executor-dev (1.13.1-1) ... 408s Selecting previously unselected package librust-async-lock-dev. 409s Preparing to unpack .../253-librust-async-lock-dev_3.4.0-4_all.deb ... 409s Unpacking librust-async-lock-dev (3.4.0-4) ... 409s Selecting previously unselected package librust-atomic-waker-dev:armhf. 409s Preparing to unpack .../254-librust-atomic-waker-dev_1.1.2-1_armhf.deb ... 409s Unpacking librust-atomic-waker-dev:armhf (1.1.2-1) ... 409s Selecting previously unselected package librust-tracing-attributes-dev:armhf. 409s Preparing to unpack .../255-librust-tracing-attributes-dev_0.1.27-1_armhf.deb ... 409s Unpacking librust-tracing-attributes-dev:armhf (0.1.27-1) ... 409s Selecting previously unselected package librust-valuable-derive-dev:armhf. 409s Preparing to unpack .../256-librust-valuable-derive-dev_0.1.0-1_armhf.deb ... 409s Unpacking librust-valuable-derive-dev:armhf (0.1.0-1) ... 409s Selecting previously unselected package librust-valuable-dev:armhf. 409s Preparing to unpack .../257-librust-valuable-dev_0.1.0-4_armhf.deb ... 409s Unpacking librust-valuable-dev:armhf (0.1.0-4) ... 409s Selecting previously unselected package librust-tracing-core-dev:armhf. 409s Preparing to unpack .../258-librust-tracing-core-dev_0.1.32-1_armhf.deb ... 409s Unpacking librust-tracing-core-dev:armhf (0.1.32-1) ... 409s Selecting previously unselected package librust-tracing-dev:armhf. 409s Preparing to unpack .../259-librust-tracing-dev_0.1.40-1_armhf.deb ... 409s Unpacking librust-tracing-dev:armhf (0.1.40-1) ... 409s Selecting previously unselected package librust-blocking-dev. 409s Preparing to unpack .../260-librust-blocking-dev_1.6.1-5_all.deb ... 409s Unpacking librust-blocking-dev (1.6.1-5) ... 409s Selecting previously unselected package librust-async-fs-dev. 409s Preparing to unpack .../261-librust-async-fs-dev_2.1.2-4_all.deb ... 409s Unpacking librust-async-fs-dev (2.1.2-4) ... 409s Selecting previously unselected package librust-bitflags-dev:armhf. 409s Preparing to unpack .../262-librust-bitflags-dev_2.6.0-1_armhf.deb ... 409s Unpacking librust-bitflags-dev:armhf (2.6.0-1) ... 409s Selecting previously unselected package librust-compiler-builtins+core-dev:armhf. 409s Preparing to unpack .../263-librust-compiler-builtins+core-dev_0.1.101-1_armhf.deb ... 409s Unpacking librust-compiler-builtins+core-dev:armhf (0.1.101-1) ... 409s Selecting previously unselected package librust-compiler-builtins+rustc-dep-of-std-dev:armhf. 409s Preparing to unpack .../264-librust-compiler-builtins+rustc-dep-of-std-dev_0.1.101-1_armhf.deb ... 409s Unpacking librust-compiler-builtins+rustc-dep-of-std-dev:armhf (0.1.101-1) ... 409s Selecting previously unselected package librust-errno-dev:armhf. 409s Preparing to unpack .../265-librust-errno-dev_0.3.8-1_armhf.deb ... 409s Unpacking librust-errno-dev:armhf (0.3.8-1) ... 409s Selecting previously unselected package librust-linux-raw-sys-dev:armhf. 409s Preparing to unpack .../266-librust-linux-raw-sys-dev_0.4.14-1_armhf.deb ... 409s Unpacking librust-linux-raw-sys-dev:armhf (0.4.14-1) ... 409s Selecting previously unselected package librust-rustix-dev:armhf. 410s Preparing to unpack .../267-librust-rustix-dev_0.38.37-1_armhf.deb ... 410s Unpacking librust-rustix-dev:armhf (0.38.37-1) ... 410s Selecting previously unselected package librust-polling-dev:armhf. 410s Preparing to unpack .../268-librust-polling-dev_3.4.0-1_armhf.deb ... 410s Unpacking librust-polling-dev:armhf (3.4.0-1) ... 410s Selecting previously unselected package librust-async-io-dev:armhf. 410s Preparing to unpack .../269-librust-async-io-dev_2.3.3-4_armhf.deb ... 410s Unpacking librust-async-io-dev:armhf (2.3.3-4) ... 410s Selecting previously unselected package librust-mio-dev:armhf. 410s Preparing to unpack .../270-librust-mio-dev_1.0.2-2_armhf.deb ... 410s Unpacking librust-mio-dev:armhf (1.0.2-2) ... 410s Selecting previously unselected package librust-owning-ref-dev:armhf. 410s Preparing to unpack .../271-librust-owning-ref-dev_0.4.1-1_armhf.deb ... 410s Unpacking librust-owning-ref-dev:armhf (0.4.1-1) ... 410s Selecting previously unselected package librust-scopeguard-dev:armhf. 410s Preparing to unpack .../272-librust-scopeguard-dev_1.2.0-1_armhf.deb ... 410s Unpacking librust-scopeguard-dev:armhf (1.2.0-1) ... 410s Selecting previously unselected package librust-lock-api-dev:armhf. 410s Preparing to unpack .../273-librust-lock-api-dev_0.4.12-1_armhf.deb ... 410s Unpacking librust-lock-api-dev:armhf (0.4.12-1) ... 410s Selecting previously unselected package librust-parking-lot-dev:armhf. 410s Preparing to unpack .../274-librust-parking-lot-dev_0.12.3-1_armhf.deb ... 410s Unpacking librust-parking-lot-dev:armhf (0.12.3-1) ... 410s Selecting previously unselected package librust-signal-hook-registry-dev:armhf. 410s Preparing to unpack .../275-librust-signal-hook-registry-dev_1.4.0-1_armhf.deb ... 410s Unpacking librust-signal-hook-registry-dev:armhf (1.4.0-1) ... 410s Selecting previously unselected package librust-socket2-dev:armhf. 410s Preparing to unpack .../276-librust-socket2-dev_0.5.7-1_armhf.deb ... 410s Unpacking librust-socket2-dev:armhf (0.5.7-1) ... 410s Selecting previously unselected package librust-tokio-macros-dev:armhf. 410s Preparing to unpack .../277-librust-tokio-macros-dev_2.4.0-2_armhf.deb ... 410s Unpacking librust-tokio-macros-dev:armhf (2.4.0-2) ... 410s Selecting previously unselected package librust-tokio-dev:armhf. 411s Preparing to unpack .../278-librust-tokio-dev_1.39.3-3_armhf.deb ... 411s Unpacking librust-tokio-dev:armhf (1.39.3-3) ... 411s Selecting previously unselected package librust-async-global-executor-dev:armhf. 411s Preparing to unpack .../279-librust-async-global-executor-dev_2.4.1-5_armhf.deb ... 411s Unpacking librust-async-global-executor-dev:armhf (2.4.1-5) ... 411s Selecting previously unselected package librust-async-net-dev. 411s Preparing to unpack .../280-librust-async-net-dev_2.0.0-4_all.deb ... 411s Unpacking librust-async-net-dev (2.0.0-4) ... 411s Selecting previously unselected package librust-async-signal-dev:armhf. 411s Preparing to unpack .../281-librust-async-signal-dev_0.2.10-1_armhf.deb ... 411s Unpacking librust-async-signal-dev:armhf (0.2.10-1) ... 411s Selecting previously unselected package librust-async-process-dev. 411s Preparing to unpack .../282-librust-async-process-dev_2.3.0-1_all.deb ... 411s Unpacking librust-async-process-dev (2.3.0-1) ... 411s Selecting previously unselected package librust-kv-log-macro-dev. 411s Preparing to unpack .../283-librust-kv-log-macro-dev_1.0.8-4_all.deb ... 411s Unpacking librust-kv-log-macro-dev (1.0.8-4) ... 411s Selecting previously unselected package librust-pin-utils-dev:armhf. 411s Preparing to unpack .../284-librust-pin-utils-dev_0.1.0-1_armhf.deb ... 411s Unpacking librust-pin-utils-dev:armhf (0.1.0-1) ... 411s Selecting previously unselected package librust-async-std-dev. 411s Preparing to unpack .../285-librust-async-std-dev_1.13.0-1_all.deb ... 411s Unpacking librust-async-std-dev (1.13.0-1) ... 411s Selecting previously unselected package librust-base64-dev:armhf. 411s Preparing to unpack .../286-librust-base64-dev_0.21.7-1_armhf.deb ... 411s Unpacking librust-base64-dev:armhf (0.21.7-1) ... 411s Selecting previously unselected package librust-bit-vec-dev:armhf. 411s Preparing to unpack .../287-librust-bit-vec-dev_0.6.3-1_armhf.deb ... 411s Unpacking librust-bit-vec-dev:armhf (0.6.3-1) ... 411s Selecting previously unselected package librust-bit-set-dev:armhf. 411s Preparing to unpack .../288-librust-bit-set-dev_0.5.2-1_armhf.deb ... 411s Unpacking librust-bit-set-dev:armhf (0.5.2-1) ... 411s Selecting previously unselected package librust-bit-set+std-dev:armhf. 412s Preparing to unpack .../289-librust-bit-set+std-dev_0.5.2-1_armhf.deb ... 412s Unpacking librust-bit-set+std-dev:armhf (0.5.2-1) ... 412s Selecting previously unselected package librust-regex-syntax-dev:armhf. 412s Preparing to unpack .../290-librust-regex-syntax-dev_0.8.5-1_armhf.deb ... 412s Unpacking librust-regex-syntax-dev:armhf (0.8.5-1) ... 412s Selecting previously unselected package librust-regex-automata-dev:armhf. 412s Preparing to unpack .../291-librust-regex-automata-dev_0.4.9-1_armhf.deb ... 412s Unpacking librust-regex-automata-dev:armhf (0.4.9-1) ... 412s Selecting previously unselected package librust-bstr-dev:armhf. 412s Preparing to unpack .../292-librust-bstr-dev_1.7.0-2build1_armhf.deb ... 412s Unpacking librust-bstr-dev:armhf (1.7.0-2build1) ... 412s Selecting previously unselected package librust-bumpalo-dev:armhf. 412s Preparing to unpack .../293-librust-bumpalo-dev_3.16.0-1_armhf.deb ... 412s Unpacking librust-bumpalo-dev:armhf (3.16.0-1) ... 412s Selecting previously unselected package librust-cast-dev:armhf. 412s Preparing to unpack .../294-librust-cast-dev_0.3.0-1_armhf.deb ... 412s Unpacking librust-cast-dev:armhf (0.3.0-1) ... 412s Selecting previously unselected package librust-iana-time-zone-dev:armhf. 412s Preparing to unpack .../295-librust-iana-time-zone-dev_0.1.60-1_armhf.deb ... 412s Unpacking librust-iana-time-zone-dev:armhf (0.1.60-1) ... 412s Selecting previously unselected package librust-wasm-bindgen-shared-dev:armhf. 412s Preparing to unpack .../296-librust-wasm-bindgen-shared-dev_0.2.87-1_armhf.deb ... 412s Unpacking librust-wasm-bindgen-shared-dev:armhf (0.2.87-1) ... 412s Selecting previously unselected package librust-wasm-bindgen-backend-dev:armhf. 412s Preparing to unpack .../297-librust-wasm-bindgen-backend-dev_0.2.87-1_armhf.deb ... 412s Unpacking librust-wasm-bindgen-backend-dev:armhf (0.2.87-1) ... 412s Selecting previously unselected package librust-wasm-bindgen-macro-support-dev:armhf. 412s Preparing to unpack .../298-librust-wasm-bindgen-macro-support-dev_0.2.87-1_armhf.deb ... 412s Unpacking librust-wasm-bindgen-macro-support-dev:armhf (0.2.87-1) ... 412s Selecting previously unselected package librust-wasm-bindgen-macro-dev:armhf. 412s Preparing to unpack .../299-librust-wasm-bindgen-macro-dev_0.2.87-1_armhf.deb ... 412s Unpacking librust-wasm-bindgen-macro-dev:armhf (0.2.87-1) ... 412s Selecting previously unselected package librust-wasm-bindgen-dev:armhf. 412s Preparing to unpack .../300-librust-wasm-bindgen-dev_0.2.87-1_armhf.deb ... 412s Unpacking librust-wasm-bindgen-dev:armhf (0.2.87-1) ... 413s Selecting previously unselected package librust-wasm-bindgen-macro-support+spans-dev:armhf. 413s Preparing to unpack .../301-librust-wasm-bindgen-macro-support+spans-dev_0.2.87-1_armhf.deb ... 413s Unpacking librust-wasm-bindgen-macro-support+spans-dev:armhf (0.2.87-1) ... 413s Selecting previously unselected package librust-wasm-bindgen-macro+spans-dev:armhf. 413s Preparing to unpack .../302-librust-wasm-bindgen-macro+spans-dev_0.2.87-1_armhf.deb ... 413s Unpacking librust-wasm-bindgen-macro+spans-dev:armhf (0.2.87-1) ... 413s Selecting previously unselected package librust-wasm-bindgen+spans-dev:armhf. 413s Preparing to unpack .../303-librust-wasm-bindgen+spans-dev_0.2.87-1_armhf.deb ... 413s Unpacking librust-wasm-bindgen+spans-dev:armhf (0.2.87-1) ... 413s Selecting previously unselected package librust-wasm-bindgen+default-dev:armhf. 413s Preparing to unpack .../304-librust-wasm-bindgen+default-dev_0.2.87-1_armhf.deb ... 413s Unpacking librust-wasm-bindgen+default-dev:armhf (0.2.87-1) ... 413s Selecting previously unselected package librust-js-sys-dev:armhf. 413s Preparing to unpack .../305-librust-js-sys-dev_0.3.64-1_armhf.deb ... 413s Unpacking librust-js-sys-dev:armhf (0.3.64-1) ... 413s Selecting previously unselected package librust-pure-rust-locales-dev:armhf. 413s Preparing to unpack .../306-librust-pure-rust-locales-dev_0.8.1-1_armhf.deb ... 413s Unpacking librust-pure-rust-locales-dev:armhf (0.8.1-1) ... 413s Selecting previously unselected package librust-chrono-dev:armhf. 413s Preparing to unpack .../307-librust-chrono-dev_0.4.38-2_armhf.deb ... 413s Unpacking librust-chrono-dev:armhf (0.4.38-2) ... 413s Selecting previously unselected package librust-regex-dev:armhf. 413s Preparing to unpack .../308-librust-regex-dev_1.10.6-1_armhf.deb ... 413s Unpacking librust-regex-dev:armhf (1.10.6-1) ... 413s Selecting previously unselected package librust-parse-zoneinfo-dev:armhf. 413s Preparing to unpack .../309-librust-parse-zoneinfo-dev_0.3.0-1_armhf.deb ... 413s Unpacking librust-parse-zoneinfo-dev:armhf (0.3.0-1) ... 413s Selecting previously unselected package librust-siphasher-dev:armhf. 413s Preparing to unpack .../310-librust-siphasher-dev_0.3.10-1_armhf.deb ... 413s Unpacking librust-siphasher-dev:armhf (0.3.10-1) ... 413s Selecting previously unselected package librust-phf-shared-dev:armhf. 413s Preparing to unpack .../311-librust-phf-shared-dev_0.11.2-1_armhf.deb ... 413s Unpacking librust-phf-shared-dev:armhf (0.11.2-1) ... 413s Selecting previously unselected package librust-phf-dev:armhf. 413s Preparing to unpack .../312-librust-phf-dev_0.11.2-1_armhf.deb ... 413s Unpacking librust-phf-dev:armhf (0.11.2-1) ... 413s Selecting previously unselected package librust-uncased-dev:armhf. 413s Preparing to unpack .../313-librust-uncased-dev_0.9.6-2_armhf.deb ... 413s Unpacking librust-uncased-dev:armhf (0.9.6-2) ... 413s Selecting previously unselected package librust-phf-shared+uncased-dev:armhf. 414s Preparing to unpack .../314-librust-phf-shared+uncased-dev_0.11.2-1_armhf.deb ... 414s Unpacking librust-phf-shared+uncased-dev:armhf (0.11.2-1) ... 414s Selecting previously unselected package librust-phf+uncased-dev:armhf. 414s Preparing to unpack .../315-librust-phf+uncased-dev_0.11.2-1_armhf.deb ... 414s Unpacking librust-phf+uncased-dev:armhf (0.11.2-1) ... 414s Selecting previously unselected package librust-ciborium-io-dev:armhf. 414s Preparing to unpack .../316-librust-ciborium-io-dev_0.2.2-1_armhf.deb ... 414s Unpacking librust-ciborium-io-dev:armhf (0.2.2-1) ... 414s Selecting previously unselected package librust-half-dev:armhf. 414s Preparing to unpack .../317-librust-half-dev_1.8.2-4_armhf.deb ... 414s Unpacking librust-half-dev:armhf (1.8.2-4) ... 414s Selecting previously unselected package librust-ciborium-ll-dev:armhf. 414s Preparing to unpack .../318-librust-ciborium-ll-dev_0.2.2-1_armhf.deb ... 414s Unpacking librust-ciborium-ll-dev:armhf (0.2.2-1) ... 414s Selecting previously unselected package librust-ciborium-dev:armhf. 414s Preparing to unpack .../319-librust-ciborium-dev_0.2.2-2_armhf.deb ... 414s Unpacking librust-ciborium-dev:armhf (0.2.2-2) ... 414s Selecting previously unselected package librust-clap-lex-dev:armhf. 414s Preparing to unpack .../320-librust-clap-lex-dev_0.7.2-2_armhf.deb ... 414s Unpacking librust-clap-lex-dev:armhf (0.7.2-2) ... 414s Selecting previously unselected package librust-strsim-dev:armhf. 414s Preparing to unpack .../321-librust-strsim-dev_0.11.1-1_armhf.deb ... 414s Unpacking librust-strsim-dev:armhf (0.11.1-1) ... 414s Selecting previously unselected package librust-terminal-size-dev:armhf. 414s Preparing to unpack .../322-librust-terminal-size-dev_0.3.0-2_armhf.deb ... 414s Unpacking librust-terminal-size-dev:armhf (0.3.0-2) ... 414s Selecting previously unselected package librust-unicase-dev:armhf. 414s Preparing to unpack .../323-librust-unicase-dev_2.7.0-1_armhf.deb ... 414s Unpacking librust-unicase-dev:armhf (2.7.0-1) ... 414s Selecting previously unselected package librust-unicode-width-dev:armhf. 414s Preparing to unpack .../324-librust-unicode-width-dev_0.1.14-1_armhf.deb ... 414s Unpacking librust-unicode-width-dev:armhf (0.1.14-1) ... 414s Selecting previously unselected package librust-clap-builder-dev:armhf. 414s Preparing to unpack .../325-librust-clap-builder-dev_4.5.15-2_armhf.deb ... 414s Unpacking librust-clap-builder-dev:armhf (4.5.15-2) ... 414s Selecting previously unselected package librust-heck-dev:armhf. 414s Preparing to unpack .../326-librust-heck-dev_0.4.1-1_armhf.deb ... 414s Unpacking librust-heck-dev:armhf (0.4.1-1) ... 414s Selecting previously unselected package librust-clap-derive-dev:armhf. 414s Preparing to unpack .../327-librust-clap-derive-dev_4.5.13-2_armhf.deb ... 414s Unpacking librust-clap-derive-dev:armhf (4.5.13-2) ... 414s Selecting previously unselected package librust-clap-dev:armhf. 414s Preparing to unpack .../328-librust-clap-dev_4.5.16-1_armhf.deb ... 414s Unpacking librust-clap-dev:armhf (4.5.16-1) ... 414s Selecting previously unselected package librust-csv-core-dev:armhf. 415s Preparing to unpack .../329-librust-csv-core-dev_0.1.11-1_armhf.deb ... 415s Unpacking librust-csv-core-dev:armhf (0.1.11-1) ... 415s Selecting previously unselected package librust-csv-dev:armhf. 415s Preparing to unpack .../330-librust-csv-dev_1.3.0-1_armhf.deb ... 415s Unpacking librust-csv-dev:armhf (1.3.0-1) ... 415s Selecting previously unselected package librust-futures-sink-dev:armhf. 415s Preparing to unpack .../331-librust-futures-sink-dev_0.3.31-1_armhf.deb ... 415s Unpacking librust-futures-sink-dev:armhf (0.3.31-1) ... 415s Selecting previously unselected package librust-futures-channel-dev:armhf. 415s Preparing to unpack .../332-librust-futures-channel-dev_0.3.30-1_armhf.deb ... 415s Unpacking librust-futures-channel-dev:armhf (0.3.30-1) ... 415s Selecting previously unselected package librust-futures-task-dev:armhf. 415s Preparing to unpack .../333-librust-futures-task-dev_0.3.30-1_armhf.deb ... 415s Unpacking librust-futures-task-dev:armhf (0.3.30-1) ... 415s Selecting previously unselected package librust-futures-macro-dev:armhf. 415s Preparing to unpack .../334-librust-futures-macro-dev_0.3.30-1_armhf.deb ... 415s Unpacking librust-futures-macro-dev:armhf (0.3.30-1) ... 415s Selecting previously unselected package librust-futures-util-dev:armhf. 415s Preparing to unpack .../335-librust-futures-util-dev_0.3.30-2_armhf.deb ... 415s Unpacking librust-futures-util-dev:armhf (0.3.30-2) ... 415s Selecting previously unselected package librust-num-cpus-dev:armhf. 415s Preparing to unpack .../336-librust-num-cpus-dev_1.16.0-1_armhf.deb ... 415s Unpacking librust-num-cpus-dev:armhf (1.16.0-1) ... 415s Selecting previously unselected package librust-futures-executor-dev:armhf. 415s Preparing to unpack .../337-librust-futures-executor-dev_0.3.30-1_armhf.deb ... 415s Unpacking librust-futures-executor-dev:armhf (0.3.30-1) ... 415s Selecting previously unselected package librust-futures-dev:armhf. 415s Preparing to unpack .../338-librust-futures-dev_0.3.30-2_armhf.deb ... 415s Unpacking librust-futures-dev:armhf (0.3.30-2) ... 415s Selecting previously unselected package librust-is-terminal-dev:armhf. 415s Preparing to unpack .../339-librust-is-terminal-dev_0.4.13-1_armhf.deb ... 415s Unpacking librust-is-terminal-dev:armhf (0.4.13-1) ... 415s Selecting previously unselected package librust-itertools-dev:armhf. 415s Preparing to unpack .../340-librust-itertools-dev_0.10.5-1_armhf.deb ... 415s Unpacking librust-itertools-dev:armhf (0.10.5-1) ... 415s Selecting previously unselected package librust-oorandom-dev:armhf. 415s Preparing to unpack .../341-librust-oorandom-dev_11.1.3-1_armhf.deb ... 415s Unpacking librust-oorandom-dev:armhf (11.1.3-1) ... 415s Selecting previously unselected package librust-winapi-i686-pc-windows-gnu-dev:armhf. 415s Preparing to unpack .../342-librust-winapi-i686-pc-windows-gnu-dev_0.4.0-1_armhf.deb ... 415s Unpacking librust-winapi-i686-pc-windows-gnu-dev:armhf (0.4.0-1) ... 416s Selecting previously unselected package librust-winapi-x86-64-pc-windows-gnu-dev:armhf. 416s Preparing to unpack .../343-librust-winapi-x86-64-pc-windows-gnu-dev_0.4.0-1_armhf.deb ... 416s Unpacking librust-winapi-x86-64-pc-windows-gnu-dev:armhf (0.4.0-1) ... 416s Selecting previously unselected package librust-winapi-dev:armhf. 416s Preparing to unpack .../344-librust-winapi-dev_0.3.9-1_armhf.deb ... 416s Unpacking librust-winapi-dev:armhf (0.3.9-1) ... 416s Selecting previously unselected package librust-dirs-sys-next-dev:armhf. 416s Preparing to unpack .../345-librust-dirs-sys-next-dev_0.1.1-1_armhf.deb ... 416s Unpacking librust-dirs-sys-next-dev:armhf (0.1.1-1) ... 416s Selecting previously unselected package librust-dirs-next-dev:armhf. 416s Preparing to unpack .../346-librust-dirs-next-dev_2.0.0-1_armhf.deb ... 416s Unpacking librust-dirs-next-dev:armhf (2.0.0-1) ... 416s Selecting previously unselected package librust-float-ord-dev:armhf. 416s Preparing to unpack .../347-librust-float-ord-dev_0.3.2-1_armhf.deb ... 416s Unpacking librust-float-ord-dev:armhf (0.3.2-1) ... 416s Selecting previously unselected package librust-cmake-dev:armhf. 416s Preparing to unpack .../348-librust-cmake-dev_0.1.45-1_armhf.deb ... 416s Unpacking librust-cmake-dev:armhf (0.1.45-1) ... 416s Selecting previously unselected package librust-freetype-sys-dev:armhf. 416s Preparing to unpack .../349-librust-freetype-sys-dev_0.13.1-1_armhf.deb ... 416s Unpacking librust-freetype-sys-dev:armhf (0.13.1-1) ... 416s Selecting previously unselected package librust-freetype-dev:armhf. 416s Preparing to unpack .../350-librust-freetype-dev_0.7.0-4_armhf.deb ... 416s Unpacking librust-freetype-dev:armhf (0.7.0-4) ... 416s Selecting previously unselected package librust-spin-dev:armhf. 416s Preparing to unpack .../351-librust-spin-dev_0.9.8-4_armhf.deb ... 416s Unpacking librust-spin-dev:armhf (0.9.8-4) ... 416s Selecting previously unselected package librust-lazy-static-dev:armhf. 416s Preparing to unpack .../352-librust-lazy-static-dev_1.5.0-1_armhf.deb ... 416s Unpacking librust-lazy-static-dev:armhf (1.5.0-1) ... 416s Selecting previously unselected package librust-pathfinder-simd-dev:armhf. 416s Preparing to unpack .../353-librust-pathfinder-simd-dev_0.5.2-1_armhf.deb ... 416s Unpacking librust-pathfinder-simd-dev:armhf (0.5.2-1) ... 416s Selecting previously unselected package librust-pathfinder-geometry-dev:armhf. 416s Preparing to unpack .../354-librust-pathfinder-geometry-dev_0.5.1-1_armhf.deb ... 416s Unpacking librust-pathfinder-geometry-dev:armhf (0.5.1-1) ... 416s Selecting previously unselected package librust-winapi-util-dev:armhf. 417s Preparing to unpack .../355-librust-winapi-util-dev_0.1.6-1_armhf.deb ... 417s Unpacking librust-winapi-util-dev:armhf (0.1.6-1) ... 417s Selecting previously unselected package librust-same-file-dev:armhf. 417s Preparing to unpack .../356-librust-same-file-dev_1.0.6-1_armhf.deb ... 417s Unpacking librust-same-file-dev:armhf (1.0.6-1) ... 417s Selecting previously unselected package librust-walkdir-dev:armhf. 417s Preparing to unpack .../357-librust-walkdir-dev_2.5.0-1_armhf.deb ... 417s Unpacking librust-walkdir-dev:armhf (2.5.0-1) ... 417s Selecting previously unselected package librust-const-cstr-dev:armhf. 417s Preparing to unpack .../358-librust-const-cstr-dev_0.3.0-1_armhf.deb ... 417s Unpacking librust-const-cstr-dev:armhf (0.3.0-1) ... 417s Selecting previously unselected package librust-libloading-dev:armhf. 417s Preparing to unpack .../359-librust-libloading-dev_0.8.5-1_armhf.deb ... 417s Unpacking librust-libloading-dev:armhf (0.8.5-1) ... 417s Selecting previously unselected package librust-dlib-dev:armhf. 417s Preparing to unpack .../360-librust-dlib-dev_0.5.2-2_armhf.deb ... 417s Unpacking librust-dlib-dev:armhf (0.5.2-2) ... 417s Selecting previously unselected package librust-yeslogic-fontconfig-sys-dev:armhf. 417s Preparing to unpack .../361-librust-yeslogic-fontconfig-sys-dev_3.0.1-1_armhf.deb ... 417s Unpacking librust-yeslogic-fontconfig-sys-dev:armhf (3.0.1-1) ... 417s Selecting previously unselected package librust-font-kit-dev:armhf. 417s Preparing to unpack .../362-librust-font-kit-dev_0.11.0-2_armhf.deb ... 417s Unpacking librust-font-kit-dev:armhf (0.11.0-2) ... 417s Selecting previously unselected package librust-color-quant-dev:armhf. 417s Preparing to unpack .../363-librust-color-quant-dev_1.1.0-1_armhf.deb ... 417s Unpacking librust-color-quant-dev:armhf (1.1.0-1) ... 417s Selecting previously unselected package librust-weezl-dev:armhf. 417s Preparing to unpack .../364-librust-weezl-dev_0.1.5-1_armhf.deb ... 417s Unpacking librust-weezl-dev:armhf (0.1.5-1) ... 417s Selecting previously unselected package librust-gif-dev:armhf. 417s Preparing to unpack .../365-librust-gif-dev_0.11.3-1_armhf.deb ... 417s Unpacking librust-gif-dev:armhf (0.11.3-1) ... 417s Selecting previously unselected package librust-jpeg-decoder-dev:armhf. 417s Preparing to unpack .../366-librust-jpeg-decoder-dev_0.3.0-1_armhf.deb ... 417s Unpacking librust-jpeg-decoder-dev:armhf (0.3.0-1) ... 417s Selecting previously unselected package librust-num-integer-dev:armhf. 417s Preparing to unpack .../367-librust-num-integer-dev_0.1.46-1_armhf.deb ... 417s Unpacking librust-num-integer-dev:armhf (0.1.46-1) ... 417s Selecting previously unselected package librust-humantime-dev:armhf. 417s Preparing to unpack .../368-librust-humantime-dev_2.1.0-1_armhf.deb ... 417s Unpacking librust-humantime-dev:armhf (2.1.0-1) ... 417s Selecting previously unselected package librust-termcolor-dev:armhf. 417s Preparing to unpack .../369-librust-termcolor-dev_1.4.1-1_armhf.deb ... 417s Unpacking librust-termcolor-dev:armhf (1.4.1-1) ... 418s Selecting previously unselected package librust-env-logger-dev:armhf. 418s Preparing to unpack .../370-librust-env-logger-dev_0.10.2-2_armhf.deb ... 418s Unpacking librust-env-logger-dev:armhf (0.10.2-2) ... 418s Selecting previously unselected package librust-quickcheck-dev:armhf. 418s Preparing to unpack .../371-librust-quickcheck-dev_1.0.3-3_armhf.deb ... 418s Unpacking librust-quickcheck-dev:armhf (1.0.3-3) ... 418s Selecting previously unselected package librust-num-bigint-dev:armhf. 418s Preparing to unpack .../372-librust-num-bigint-dev_0.4.6-1_armhf.deb ... 418s Unpacking librust-num-bigint-dev:armhf (0.4.6-1) ... 418s Selecting previously unselected package librust-num-rational-dev:armhf. 418s Preparing to unpack .../373-librust-num-rational-dev_0.4.2-1_armhf.deb ... 418s Unpacking librust-num-rational-dev:armhf (0.4.2-1) ... 418s Selecting previously unselected package librust-png-dev:armhf. 418s Preparing to unpack .../374-librust-png-dev_0.17.7-3_armhf.deb ... 418s Unpacking librust-png-dev:armhf (0.17.7-3) ... 418s Selecting previously unselected package librust-qoi-dev:armhf. 418s Preparing to unpack .../375-librust-qoi-dev_0.4.1-2_armhf.deb ... 418s Unpacking librust-qoi-dev:armhf (0.4.1-2) ... 418s Selecting previously unselected package librust-tiff-dev:armhf. 418s Preparing to unpack .../376-librust-tiff-dev_0.9.0-1_armhf.deb ... 418s Unpacking librust-tiff-dev:armhf (0.9.0-1) ... 418s Selecting previously unselected package libsharpyuv0:armhf. 418s Preparing to unpack .../377-libsharpyuv0_1.4.0-0.1_armhf.deb ... 418s Unpacking libsharpyuv0:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libwebp7:armhf. 418s Preparing to unpack .../378-libwebp7_1.4.0-0.1_armhf.deb ... 418s Unpacking libwebp7:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libwebpdemux2:armhf. 418s Preparing to unpack .../379-libwebpdemux2_1.4.0-0.1_armhf.deb ... 418s Unpacking libwebpdemux2:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libwebpmux3:armhf. 418s Preparing to unpack .../380-libwebpmux3_1.4.0-0.1_armhf.deb ... 418s Unpacking libwebpmux3:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libwebpdecoder3:armhf. 418s Preparing to unpack .../381-libwebpdecoder3_1.4.0-0.1_armhf.deb ... 418s Unpacking libwebpdecoder3:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libsharpyuv-dev:armhf. 418s Preparing to unpack .../382-libsharpyuv-dev_1.4.0-0.1_armhf.deb ... 418s Unpacking libsharpyuv-dev:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package libwebp-dev:armhf. 418s Preparing to unpack .../383-libwebp-dev_1.4.0-0.1_armhf.deb ... 418s Unpacking libwebp-dev:armhf (1.4.0-0.1) ... 418s Selecting previously unselected package librust-libwebp-sys-dev:armhf. 419s Preparing to unpack .../384-librust-libwebp-sys-dev_0.9.5-1build1_armhf.deb ... 419s Unpacking librust-libwebp-sys-dev:armhf (0.9.5-1build1) ... 419s Selecting previously unselected package librust-webp-dev:armhf. 419s Preparing to unpack .../385-librust-webp-dev_0.2.6-1_armhf.deb ... 419s Unpacking librust-webp-dev:armhf (0.2.6-1) ... 419s Selecting previously unselected package librust-image-dev:armhf. 419s Preparing to unpack .../386-librust-image-dev_0.24.7-2_armhf.deb ... 419s Unpacking librust-image-dev:armhf (0.24.7-2) ... 419s Selecting previously unselected package librust-plotters-backend-dev:armhf. 419s Preparing to unpack .../387-librust-plotters-backend-dev_0.3.7-1_armhf.deb ... 419s Unpacking librust-plotters-backend-dev:armhf (0.3.7-1) ... 419s Selecting previously unselected package librust-plotters-bitmap-dev:armhf. 419s Preparing to unpack .../388-librust-plotters-bitmap-dev_0.3.3-3_armhf.deb ... 419s Unpacking librust-plotters-bitmap-dev:armhf (0.3.3-3) ... 419s Selecting previously unselected package librust-plotters-svg-dev:armhf. 419s Preparing to unpack .../389-librust-plotters-svg-dev_0.3.5-1_armhf.deb ... 419s Unpacking librust-plotters-svg-dev:armhf (0.3.5-1) ... 419s Selecting previously unselected package librust-web-sys-dev:armhf. 419s Preparing to unpack .../390-librust-web-sys-dev_0.3.64-2_armhf.deb ... 419s Unpacking librust-web-sys-dev:armhf (0.3.64-2) ... 420s Selecting previously unselected package librust-plotters-dev:armhf. 420s Preparing to unpack .../391-librust-plotters-dev_0.3.5-4_armhf.deb ... 420s Unpacking librust-plotters-dev:armhf (0.3.5-4) ... 420s Selecting previously unselected package librust-smol-dev. 420s Preparing to unpack .../392-librust-smol-dev_2.0.2-1_all.deb ... 420s Unpacking librust-smol-dev (2.0.2-1) ... 420s Selecting previously unselected package librust-tinytemplate-dev:armhf. 420s Preparing to unpack .../393-librust-tinytemplate-dev_1.2.1-1_armhf.deb ... 420s Unpacking librust-tinytemplate-dev:armhf (1.2.1-1) ... 420s Selecting previously unselected package librust-criterion-dev. 420s Preparing to unpack .../394-librust-criterion-dev_0.5.1-6_all.deb ... 420s Unpacking librust-criterion-dev (0.5.1-6) ... 420s Selecting previously unselected package librust-phf-generator-dev:armhf. 420s Preparing to unpack .../395-librust-phf-generator-dev_0.11.2-2_armhf.deb ... 420s Unpacking librust-phf-generator-dev:armhf (0.11.2-2) ... 420s Selecting previously unselected package librust-phf-codegen-dev:armhf. 420s Preparing to unpack .../396-librust-phf-codegen-dev_0.11.2-1_armhf.deb ... 420s Unpacking librust-phf-codegen-dev:armhf (0.11.2-1) ... 420s Selecting previously unselected package librust-chrono-tz-build-dev:armhf. 420s Preparing to unpack .../397-librust-chrono-tz-build-dev_0.2.1-1_armhf.deb ... 420s Unpacking librust-chrono-tz-build-dev:armhf (0.2.1-1) ... 420s Selecting previously unselected package librust-chrono-tz-dev:armhf. 420s Preparing to unpack .../398-librust-chrono-tz-dev_0.8.6-2_armhf.deb ... 420s Unpacking librust-chrono-tz-dev:armhf (0.8.6-2) ... 420s Selecting previously unselected package librust-ctor-dev:armhf. 420s Preparing to unpack .../399-librust-ctor-dev_0.1.26-1_armhf.deb ... 420s Unpacking librust-ctor-dev:armhf (0.1.26-1) ... 420s Selecting previously unselected package librust-powerfmt-macros-dev:armhf. 420s Preparing to unpack .../400-librust-powerfmt-macros-dev_0.1.0-1_armhf.deb ... 420s Unpacking librust-powerfmt-macros-dev:armhf (0.1.0-1) ... 420s Selecting previously unselected package librust-powerfmt-dev:armhf. 420s Preparing to unpack .../401-librust-powerfmt-dev_0.2.0-1_armhf.deb ... 420s Unpacking librust-powerfmt-dev:armhf (0.2.0-1) ... 420s Selecting previously unselected package librust-deranged-dev:armhf. 420s Preparing to unpack .../402-librust-deranged-dev_0.3.11-1_armhf.deb ... 420s Unpacking librust-deranged-dev:armhf (0.3.11-1) ... 421s Selecting previously unselected package librust-eui48-dev:armhf. 421s Preparing to unpack .../403-librust-eui48-dev_1.1.0-2_armhf.deb ... 421s Unpacking librust-eui48-dev:armhf (1.1.0-2) ... 421s Selecting previously unselected package librust-indenter-dev:armhf. 421s Preparing to unpack .../404-librust-indenter-dev_0.3.3-1_armhf.deb ... 421s Unpacking librust-indenter-dev:armhf (0.3.3-1) ... 421s Selecting previously unselected package librust-eyre-dev:armhf. 421s Preparing to unpack .../405-librust-eyre-dev_0.6.12-1_armhf.deb ... 421s Unpacking librust-eyre-dev:armhf (0.6.12-1) ... 421s Selecting previously unselected package librust-eyre+default-dev:armhf. 421s Preparing to unpack .../406-librust-eyre+default-dev_0.6.12-1_armhf.deb ... 421s Unpacking librust-eyre+default-dev:armhf (0.6.12-1) ... 421s Selecting previously unselected package librust-fancy-regex-dev:armhf. 421s Preparing to unpack .../407-librust-fancy-regex-dev_0.11.0-2_armhf.deb ... 421s Unpacking librust-fancy-regex-dev:armhf (0.11.0-2) ... 421s Selecting previously unselected package librust-fnv-dev:armhf. 421s Preparing to unpack .../408-librust-fnv-dev_1.0.7-1_armhf.deb ... 421s Unpacking librust-fnv-dev:armhf (1.0.7-1) ... 421s Selecting previously unselected package librust-geo-types-dev:armhf. 421s Preparing to unpack .../409-librust-geo-types-dev_0.7.11-2_armhf.deb ... 421s Unpacking librust-geo-types-dev:armhf (0.7.11-2) ... 421s Selecting previously unselected package librust-ghost-dev:armhf. 421s Preparing to unpack .../410-librust-ghost-dev_0.1.5-1_armhf.deb ... 421s Unpacking librust-ghost-dev:armhf (0.1.5-1) ... 421s Selecting previously unselected package librust-hmac-dev:armhf. 421s Preparing to unpack .../411-librust-hmac-dev_0.12.1-1_armhf.deb ... 421s Unpacking librust-hmac-dev:armhf (0.12.1-1) ... 421s Selecting previously unselected package librust-indoc-dev:armhf. 421s Preparing to unpack .../412-librust-indoc-dev_2.0.5-1_armhf.deb ... 421s Unpacking librust-indoc-dev:armhf (2.0.5-1) ... 421s Selecting previously unselected package librust-inventory-dev:armhf. 421s Preparing to unpack .../413-librust-inventory-dev_0.3.2-1_armhf.deb ... 421s Unpacking librust-inventory-dev:armhf (0.3.2-1) ... 421s Selecting previously unselected package librust-memoffset-dev:armhf. 421s Preparing to unpack .../414-librust-memoffset-dev_0.8.0-1_armhf.deb ... 421s Unpacking librust-memoffset-dev:armhf (0.8.0-1) ... 422s Selecting previously unselected package librust-num-conv-dev:armhf. 422s Preparing to unpack .../415-librust-num-conv-dev_0.1.0-1_armhf.deb ... 422s Unpacking librust-num-conv-dev:armhf (0.1.0-1) ... 422s Selecting previously unselected package librust-num-threads-dev:armhf. 422s Preparing to unpack .../416-librust-num-threads-dev_0.1.7-1_armhf.deb ... 422s Unpacking librust-num-threads-dev:armhf (0.1.7-1) ... 422s Selecting previously unselected package librust-postgres-derive-dev:armhf. 422s Preparing to unpack .../417-librust-postgres-derive-dev_0.4.5-1_armhf.deb ... 422s Unpacking librust-postgres-derive-dev:armhf (0.4.5-1) ... 422s Selecting previously unselected package librust-sha2-asm-dev:armhf. 422s Preparing to unpack .../418-librust-sha2-asm-dev_0.6.2-2_armhf.deb ... 422s Unpacking librust-sha2-asm-dev:armhf (0.6.2-2) ... 422s Selecting previously unselected package librust-sha2-dev:armhf. 422s Preparing to unpack .../419-librust-sha2-dev_0.10.8-1_armhf.deb ... 422s Unpacking librust-sha2-dev:armhf (0.10.8-1) ... 422s Selecting previously unselected package librust-unicode-bidi-dev:armhf. 422s Preparing to unpack .../420-librust-unicode-bidi-dev_0.3.13-1_armhf.deb ... 422s Unpacking librust-unicode-bidi-dev:armhf (0.3.13-1) ... 422s Selecting previously unselected package librust-unicode-normalization-dev:armhf. 422s Preparing to unpack .../421-librust-unicode-normalization-dev_0.1.22-1_armhf.deb ... 422s Unpacking librust-unicode-normalization-dev:armhf (0.1.22-1) ... 422s Selecting previously unselected package librust-stringprep-dev:armhf. 422s Preparing to unpack .../422-librust-stringprep-dev_0.1.2-1_armhf.deb ... 422s Unpacking librust-stringprep-dev:armhf (0.1.2-1) ... 422s Selecting previously unselected package librust-postgres-protocol-dev:armhf. 422s Preparing to unpack .../423-librust-postgres-protocol-dev_0.6.6-2_armhf.deb ... 422s Unpacking librust-postgres-protocol-dev:armhf (0.6.6-2) ... 422s Selecting previously unselected package librust-time-core-dev:armhf. 422s Preparing to unpack .../424-librust-time-core-dev_0.1.2-1_armhf.deb ... 422s Unpacking librust-time-core-dev:armhf (0.1.2-1) ... 422s Selecting previously unselected package librust-time-macros-dev:armhf. 422s Preparing to unpack .../425-librust-time-macros-dev_0.2.16-1_armhf.deb ... 422s Unpacking librust-time-macros-dev:armhf (0.2.16-1) ... 422s Selecting previously unselected package librust-time-dev:armhf. 423s Preparing to unpack .../426-librust-time-dev_0.3.36-2_armhf.deb ... 423s Unpacking librust-time-dev:armhf (0.3.36-2) ... 423s Selecting previously unselected package librust-postgres-types-dev:armhf. 423s Preparing to unpack .../427-librust-postgres-types-dev_0.2.6-2_armhf.deb ... 423s Unpacking librust-postgres-types-dev:armhf (0.2.6-2) ... 423s Selecting previously unselected package librust-rand-xorshift-dev:armhf. 423s Preparing to unpack .../428-librust-rand-xorshift-dev_0.3.0-2_armhf.deb ... 423s Unpacking librust-rand-xorshift-dev:armhf (0.3.0-2) ... 423s Selecting previously unselected package librust-quick-error-dev:armhf. 423s Preparing to unpack .../429-librust-quick-error-dev_2.0.1-1_armhf.deb ... 423s Unpacking librust-quick-error-dev:armhf (2.0.1-1) ... 423s Selecting previously unselected package librust-tempfile-dev:armhf. 423s Preparing to unpack .../430-librust-tempfile-dev_3.13.0-1_armhf.deb ... 423s Unpacking librust-tempfile-dev:armhf (3.13.0-1) ... 423s Selecting previously unselected package librust-rusty-fork-dev:armhf. 423s Preparing to unpack .../431-librust-rusty-fork-dev_0.3.0-1_armhf.deb ... 423s Unpacking librust-rusty-fork-dev:armhf (0.3.0-1) ... 423s Selecting previously unselected package librust-wait-timeout-dev:armhf. 423s Preparing to unpack .../432-librust-wait-timeout-dev_0.2.0-1_armhf.deb ... 423s Unpacking librust-wait-timeout-dev:armhf (0.2.0-1) ... 423s Selecting previously unselected package librust-rusty-fork+wait-timeout-dev:armhf. 423s Preparing to unpack .../433-librust-rusty-fork+wait-timeout-dev_0.3.0-1_armhf.deb ... 423s Unpacking librust-rusty-fork+wait-timeout-dev:armhf (0.3.0-1) ... 423s Selecting previously unselected package librust-unarray-dev:armhf. 423s Preparing to unpack .../434-librust-unarray-dev_0.1.4-1_armhf.deb ... 423s Unpacking librust-unarray-dev:armhf (0.1.4-1) ... 423s Selecting previously unselected package librust-proptest-dev:armhf. 423s Preparing to unpack .../435-librust-proptest-dev_1.5.0-2_armhf.deb ... 423s Unpacking librust-proptest-dev:armhf (1.5.0-2) ... 423s Selecting previously unselected package llvm-19-runtime. 423s Preparing to unpack .../436-llvm-19-runtime_1%3a19.1.2-1ubuntu1_armhf.deb ... 423s Unpacking llvm-19-runtime (1:19.1.2-1ubuntu1) ... 423s Selecting previously unselected package llvm-runtime:armhf. 423s Preparing to unpack .../437-llvm-runtime_1%3a19.0-60~exp1_armhf.deb ... 423s Unpacking llvm-runtime:armhf (1:19.0-60~exp1) ... 424s Selecting previously unselected package llvm-19-linker-tools. 424s Preparing to unpack .../438-llvm-19-linker-tools_1%3a19.1.2-1ubuntu1_armhf.deb ... 424s Unpacking llvm-19-linker-tools (1:19.1.2-1ubuntu1) ... 424s Selecting previously unselected package libpfm4:armhf. 424s Preparing to unpack .../439-libpfm4_4.13.0+git83-g91970fe-1_armhf.deb ... 424s Unpacking libpfm4:armhf (4.13.0+git83-g91970fe-1) ... 424s Selecting previously unselected package llvm-19. 424s Preparing to unpack .../440-llvm-19_1%3a19.1.2-1ubuntu1_armhf.deb ... 424s Unpacking llvm-19 (1:19.1.2-1ubuntu1) ... 424s Selecting previously unselected package llvm. 424s Preparing to unpack .../441-llvm_1%3a19.0-60~exp1_armhf.deb ... 424s Unpacking llvm (1:19.0-60~exp1) ... 425s Selecting previously unselected package binutils-mingw-w64-x86-64. 425s Preparing to unpack .../442-binutils-mingw-w64-x86-64_2.43.1-4ubuntu1+12_armhf.deb ... 425s Unpacking binutils-mingw-w64-x86-64 (2.43.1-4ubuntu1+12) ... 425s Selecting previously unselected package binutils-mingw-w64-i686. 425s Preparing to unpack .../443-binutils-mingw-w64-i686_2.43.1-4ubuntu1+12_armhf.deb ... 425s Unpacking binutils-mingw-w64-i686 (2.43.1-4ubuntu1+12) ... 425s Selecting previously unselected package librust-python3-dll-a-dev:armhf. 425s Preparing to unpack .../444-librust-python3-dll-a-dev_0.2.10-1_armhf.deb ... 425s Unpacking librust-python3-dll-a-dev:armhf (0.2.10-1) ... 425s Selecting previously unselected package librust-target-lexicon-dev:armhf. 425s Preparing to unpack .../445-librust-target-lexicon-dev_0.12.14-1_armhf.deb ... 425s Unpacking librust-target-lexicon-dev:armhf (0.12.14-1) ... 425s Selecting previously unselected package librust-pyo3-build-config-dev:armhf. 425s Preparing to unpack .../446-librust-pyo3-build-config-dev_0.22.6-1_armhf.deb ... 425s Unpacking librust-pyo3-build-config-dev:armhf (0.22.6-1) ... 425s Selecting previously unselected package python3.12-dev. 425s Preparing to unpack .../447-python3.12-dev_3.12.7-3_armhf.deb ... 425s Unpacking python3.12-dev (3.12.7-3) ... 425s Selecting previously unselected package librust-pyo3-ffi-dev:armhf. 425s Preparing to unpack .../448-librust-pyo3-ffi-dev_0.22.6-1build1_armhf.deb ... 425s Unpacking librust-pyo3-ffi-dev:armhf (0.22.6-1build1) ... 425s Selecting previously unselected package librust-pyo3-macros-backend-dev:armhf. 425s Preparing to unpack .../449-librust-pyo3-macros-backend-dev_0.22.6-1_armhf.deb ... 425s Unpacking librust-pyo3-macros-backend-dev:armhf (0.22.6-1) ... 425s Selecting previously unselected package librust-pyo3-macros-dev:armhf. 425s Preparing to unpack .../450-librust-pyo3-macros-dev_0.22.6-1_armhf.deb ... 425s Unpacking librust-pyo3-macros-dev:armhf (0.22.6-1) ... 426s Selecting previously unselected package librust-rust-decimal-dev:armhf. 426s Preparing to unpack .../451-librust-rust-decimal-dev_1.36.0-1_armhf.deb ... 426s Unpacking librust-rust-decimal-dev:armhf (1.36.0-1) ... 426s Selecting previously unselected package librust-unindent-dev:armhf. 426s Preparing to unpack .../452-librust-unindent-dev_0.2.3-1_armhf.deb ... 426s Unpacking librust-unindent-dev:armhf (0.2.3-1) ... 426s Selecting previously unselected package librust-pyo3-dev:armhf. 426s Preparing to unpack .../453-librust-pyo3-dev_0.22.6-1_armhf.deb ... 426s Unpacking librust-pyo3-dev:armhf (0.22.6-1) ... 426s Selecting previously unselected package librust-rustc-hash-dev:armhf. 426s Preparing to unpack .../454-librust-rustc-hash-dev_1.1.0-1_armhf.deb ... 426s Unpacking librust-rustc-hash-dev:armhf (1.1.0-1) ... 426s Selecting previously unselected package pybuild-plugin-autopkgtest. 426s Preparing to unpack .../455-pybuild-plugin-autopkgtest_6.20241024_all.deb ... 426s Unpacking pybuild-plugin-autopkgtest (6.20241024) ... 426s Selecting previously unselected package python3-packaging. 426s Preparing to unpack .../456-python3-packaging_24.2-1_all.deb ... 426s Unpacking python3-packaging (24.2-1) ... 426s Selecting previously unselected package python3-pyproject-hooks. 426s Preparing to unpack .../457-python3-pyproject-hooks_1.2.0-1_all.deb ... 426s Unpacking python3-pyproject-hooks (1.2.0-1) ... 426s Selecting previously unselected package python3-toml. 426s Preparing to unpack .../458-python3-toml_0.10.2-1_all.deb ... 426s Unpacking python3-toml (0.10.2-1) ... 426s Selecting previously unselected package python3-wheel. 426s Preparing to unpack .../459-python3-wheel_0.45.1-1_all.deb ... 426s Unpacking python3-wheel (0.45.1-1) ... 426s Selecting previously unselected package python3-build. 426s Preparing to unpack .../460-python3-build_1.2.2-1_all.deb ... 426s Unpacking python3-build (1.2.2-1) ... 426s Selecting previously unselected package python3-installer. 426s Preparing to unpack .../461-python3-installer_0.7.0+dfsg1-3_all.deb ... 426s Unpacking python3-installer (0.7.0+dfsg1-3) ... 426s Selecting previously unselected package pybuild-plugin-pyproject. 426s Preparing to unpack .../462-pybuild-plugin-pyproject_6.20241024_all.deb ... 426s Unpacking pybuild-plugin-pyproject (6.20241024) ... 426s Selecting previously unselected package python3.13. 427s Preparing to unpack .../463-python3.13_3.13.0-2_armhf.deb ... 427s Unpacking python3.13 (3.13.0-2) ... 427s Selecting previously unselected package python3-all. 427s Preparing to unpack .../464-python3-all_3.12.7-1_armhf.deb ... 427s Unpacking python3-all (3.12.7-1) ... 427s Selecting previously unselected package python3-dateutil. 427s Preparing to unpack .../465-python3-dateutil_2.9.0-3_all.deb ... 427s Unpacking python3-dateutil (2.9.0-3) ... 427s Selecting previously unselected package python3-sortedcontainers. 427s Preparing to unpack .../466-python3-sortedcontainers_2.4.0-2_all.deb ... 427s Unpacking python3-sortedcontainers (2.4.0-2) ... 427s Selecting previously unselected package python3-hypothesis. 427s Preparing to unpack .../467-python3-hypothesis_6.119.3-1_all.deb ... 427s Unpacking python3-hypothesis (6.119.3-1) ... 427s Selecting previously unselected package python3-iniconfig. 427s Preparing to unpack .../468-python3-iniconfig_1.1.1-2_all.deb ... 427s Unpacking python3-iniconfig (1.1.1-2) ... 427s Selecting previously unselected package python3-pluggy. 427s Preparing to unpack .../469-python3-pluggy_1.5.0-1_all.deb ... 427s Unpacking python3-pluggy (1.5.0-1) ... 427s Selecting previously unselected package python3-pytest. 427s Preparing to unpack .../470-python3-pytest_8.3.3-1_all.deb ... 427s Unpacking python3-pytest (8.3.3-1) ... 427s Selecting previously unselected package python3-regex. 427s Preparing to unpack .../471-python3-regex_0.1.20240724-1build1_armhf.deb ... 427s Unpacking python3-regex (0.1.20240724-1build1) ... 427s Selecting previously unselected package python3-semantic-version. 427s Preparing to unpack .../472-python3-semantic-version_2.10.0-2_all.deb ... 427s Unpacking python3-semantic-version (2.10.0-2) ... 427s Selecting previously unselected package rustc. 427s Preparing to unpack .../473-rustc_1.80.1ubuntu2_armhf.deb ... 427s Unpacking rustc (1.80.1ubuntu2) ... 427s Selecting previously unselected package cargo. 427s Preparing to unpack .../474-cargo_1.80.1ubuntu2_armhf.deb ... 427s Unpacking cargo (1.80.1ubuntu2) ... 427s Selecting previously unselected package python3-setuptools-rust. 427s Preparing to unpack .../475-python3-setuptools-rust_1.9.0+dfsg-2_all.deb ... 427s Unpacking python3-setuptools-rust (1.9.0+dfsg-2) ... 427s Selecting previously unselected package python3-tiktoken. 428s Preparing to unpack .../476-python3-tiktoken_0.8.0-1build1_armhf.deb ... 428s Unpacking python3-tiktoken (0.8.0-1build1) ... 428s Setting up dh-python (6.20241024) ... 428s Setting up librust-ciborium-io-dev:armhf (0.2.2-1) ... 428s Setting up librust-crossbeam-utils-dev:armhf (0.8.19-1) ... 428s Setting up librust-parking-dev:armhf (2.2.0-1) ... 428s Setting up librust-ppv-lite86-dev:armhf (0.2.16-1) ... 428s Setting up python3-iniconfig (1.1.1-2) ... 428s Setting up libllvm19:armhf (1:19.1.2-1ubuntu1) ... 428s Setting up libsharpyuv0:armhf (1.4.0-0.1) ... 428s Setting up librust-pin-utils-dev:armhf (0.1.0-1) ... 428s Setting up librust-fnv-dev:armhf (1.0.7-1) ... 428s Setting up librust-unindent-dev:armhf (0.2.3-1) ... 428s Setting up librust-quick-error-dev:armhf (2.0.1-1) ... 428s Setting up librust-traitobject-dev:armhf (0.1.0-1) ... 428s Setting up librust-either-dev:armhf (1.13.0-1) ... 428s Setting up binutils-mingw-w64-x86-64 (2.43.1-4ubuntu1+12) ... 428s Setting up librust-adler-dev:armhf (1.0.2-2) ... 428s Setting up librust-version-check-dev:armhf (0.9.5-1) ... 428s Setting up librust-base64-dev:armhf (0.21.7-1) ... 428s Setting up librust-indoc-dev:armhf (2.0.5-1) ... 428s Setting up librust-anstyle-dev:armhf (1.0.8-1) ... 428s Setting up librust-winapi-i686-pc-windows-gnu-dev:armhf (0.4.0-1) ... 428s Setting up librust-futures-task-dev:armhf (0.3.30-1) ... 428s Setting up librust-rustc-hash-dev:armhf (1.1.0-1) ... 428s Setting up librust-wasm-bindgen-shared-dev:armhf (0.2.87-1) ... 428s Setting up libarchive-zip-perl (1.68-1) ... 428s Setting up librust-colorchoice-dev:armhf (1.0.0-1) ... 428s Setting up librust-fastrand-dev:armhf (2.1.1-1) ... 428s Setting up libdebhelper-perl (13.20ubuntu1) ... 428s Setting up librust-unsafe-any-dev:armhf (0.4.2-2) ... 428s Setting up librust-tinyvec-macros-dev:armhf (0.1.0-1) ... 428s Setting up librust-libm-dev:armhf (0.2.8-1) ... 428s Setting up librust-strsim-dev:armhf (0.11.1-1) ... 428s Setting up linux-libc-dev:armhf (6.11.0-8.8) ... 428s Setting up libwebpdecoder3:armhf (1.4.0-0.1) ... 428s Setting up m4 (1.4.19-4build1) ... 428s Setting up librust-rustc-demangle-dev:armhf (0.1.21-1) ... 428s Setting up librust-const-cstr-dev:armhf (0.3.0-1) ... 428s Setting up librust-fallible-iterator-dev:armhf (0.3.0-2) ... 428s Setting up librust-ryu-dev:armhf (1.0.15-1) ... 428s Setting up python3-sortedcontainers (2.4.0-2) ... 429s Setting up librust-humantime-dev:armhf (2.1.0-1) ... 429s Setting up librust-anstyle-query-dev:armhf (1.0.0-1) ... 429s Setting up librust-cast-dev:armhf (0.3.0-1) ... 429s Setting up libgomp1:armhf (14.2.0-9ubuntu1) ... 429s Setting up librust-subtle-dev:armhf (2.6.1-1) ... 429s Setting up librust-simdutf8-dev:armhf (0.1.4-4) ... 429s Setting up librust-atomic-waker-dev:armhf (1.1.2-1) ... 429s Setting up librust-miniz-oxide-dev:armhf (0.7.1-1) ... 429s Setting up librust-pin-project-lite-dev:armhf (0.2.13-1) ... 429s Setting up python3-wheel (0.45.1-1) ... 429s Setting up librust-unicode-segmentation-dev:armhf (1.11.0-1) ... 429s Setting up librust-typemap-dev:armhf (0.3.3-2) ... 429s Setting up libpython3.12t64:armhf (3.12.7-3) ... 429s Setting up libpython3.13-minimal:armhf (3.13.0-2) ... 429s Setting up librust-compiler-builtins-dev:armhf (0.1.101-1) ... 429s Setting up librust-weezl-dev:armhf (0.1.5-1) ... 429s Setting up librust-utf8parse-dev:armhf (0.2.1-1) ... 429s Setting up librust-crossbeam-epoch-dev:armhf (0.9.18-1) ... 429s Setting up autotools-dev (20220109.1) ... 429s Setting up librust-tap-dev:armhf (1.0.1-1) ... 429s Setting up python3-packaging (24.2-1) ... 429s Setting up librust-array-init-dev:armhf (2.0.1-1) ... 429s Setting up libpkgconf3:armhf (1.8.1-4) ... 429s Setting up libpfm4:armhf (4.13.0+git83-g91970fe-1) ... 429s Setting up rpcsvc-proto (1.4.2-0ubuntu7) ... 429s Setting up librust-oorandom-dev:armhf (11.1.3-1) ... 429s Setting up python3-pyproject-hooks (1.2.0-1) ... 430s Setting up libfreetype6:armhf (2.13.3+dfsg-1) ... 430s Setting up librust-rustc-std-workspace-core-dev:armhf (1.0.0-1) ... 430s Setting up librust-funty-dev:armhf (2.0.0-1) ... 430s Setting up librust-futures-io-dev:armhf (0.3.31-1) ... 430s Setting up librust-typenum-dev:armhf (1.17.0-2) ... 430s Setting up librust-core-maths-dev:armhf (0.1.0-2) ... 430s Setting up librust-stable-deref-trait-dev:armhf (1.2.0-1) ... 430s Setting up librust-critical-section-dev:armhf (1.1.3-1) ... 430s Setting up librust-scopeguard-dev:armhf (1.2.0-1) ... 430s Setting up librust-iana-time-zone-dev:armhf (0.1.60-1) ... 430s Setting up fonts-dejavu-mono (2.37-8) ... 430s Setting up libmpc3:armhf (1.3.1-1build2) ... 430s Setting up librust-rand-core-dev:armhf (0.6.4-2) ... 430s Setting up python3-semantic-version (2.10.0-2) ... 430s Setting up autopoint (0.22.5-2) ... 430s Setting up libjsoncpp25:armhf (1.9.5-6build1) ... 430s Setting up fonts-dejavu-core (2.37-8) ... 430s Setting up librust-seahash-dev:armhf (4.1.0-1) ... 430s Setting up pkgconf-bin (1.8.1-4) ... 430s Setting up librust-ab-glyph-rasterizer-dev:armhf (0.1.7-1) ... 430s Setting up binutils-mingw-w64-i686 (2.43.1-4ubuntu1+12) ... 430s Setting up librust-time-core-dev:armhf (0.1.2-1) ... 430s Setting up python3-regex (0.1.20240724-1build1) ... 431s Setting up librust-crunchy-dev:armhf (0.2.2-1) ... 431s Setting up python3-toml (0.10.2-1) ... 431s Setting up librust-unicase-dev:armhf (2.7.0-1) ... 431s Setting up librust-unicode-width-dev:armhf (0.1.14-1) ... 431s Setting up python3-installer (0.7.0+dfsg1-3) ... 431s Setting up autoconf (2.72-3) ... 431s Setting up python3-pluggy (1.5.0-1) ... 431s Setting up libwebp7:armhf (1.4.0-0.1) ... 431s Setting up libubsan1:armhf (14.2.0-9ubuntu1) ... 431s Setting up librust-unicode-ident-dev:armhf (1.0.13-1) ... 431s Setting up librust-equivalent-dev:armhf (1.0.1-1) ... 431s Setting up dwz (0.15-1build6) ... 431s Setting up librust-bitflags-1-dev:armhf (1.3.2-5) ... 431s Setting up librust-uncased-dev:armhf (0.9.6-2) ... 431s Setting up librust-slog-dev:armhf (2.7.0-1) ... 431s Setting up python3-tiktoken (0.8.0-1build1) ... 432s Setting up librust-pure-rust-locales-dev:armhf (0.8.1-1) ... 432s Setting up librhash0:armhf (1.4.3-3build1) ... 432s Setting up libcrypt-dev:armhf (1:4.4.36-5) ... 432s Setting up libasan8:armhf (14.2.0-9ubuntu1) ... 432s Setting up librust-ttf-parser-dev:armhf (0.24.1-1) ... 432s Setting up librust-cfg-if-dev:armhf (1.0.0-1) ... 432s Setting up debugedit (1:5.1-1) ... 432s Setting up librust-color-quant-dev:armhf (1.1.0-1) ... 432s Setting up python3.13-minimal (3.13.0-2) ... 433s Setting up python3-dateutil (2.9.0-3) ... 433s Setting up librust-blobby-dev:armhf (0.3.1-1) ... 433s Setting up cmake-data (3.30.3-1) ... 433s Setting up llvm-19-linker-tools (1:19.1.2-1ubuntu1) ... 433s Setting up librust-byteorder-dev:armhf (1.5.0-1) ... 433s Setting up librust-static-assertions-dev:armhf (1.1.0-1) ... 433s Setting up librust-compiler-builtins+core-dev:armhf (0.1.101-1) ... 433s Setting up librust-float-ord-dev:armhf (0.3.2-1) ... 433s Setting up librust-autocfg-dev:armhf (1.1.0-1) ... 433s Setting up libgcc-14-dev:armhf (14.2.0-9ubuntu1) ... 433s Setting up libisl23:armhf (0.27-1) ... 433s Setting up librust-time-macros-dev:armhf (0.2.16-1) ... 433s Setting up llvm-19-runtime (1:19.1.2-1ubuntu1) ... 433s Setting up librust-futures-sink-dev:armhf (0.3.31-1) ... 433s Setting up python3-build (1.2.2-1) ... 433s Setting up libsharpyuv-dev:armhf (1.4.0-0.1) ... 433s Setting up libc-dev-bin (2.40-1ubuntu3) ... 433s Setting up librust-cfg-if-0.1-dev:armhf (0.1.10-3) ... 433s Setting up librust-tinyvec-dev:armhf (1.6.0-2) ... 433s Setting up libwebpmux3:armhf (1.4.0-0.1) ... 433s Setting up librust-plotters-backend-dev:armhf (0.3.7-1) ... 433s Setting up librust-shlex-dev:armhf (1.3.0-1) ... 433s Setting up libpython3.13-stdlib:armhf (3.13.0-2) ... 433s Setting up librust-indenter-dev:armhf (0.3.3-1) ... 433s Setting up librust-cpp-demangle-dev:armhf (0.4.0-1) ... 433s Setting up librust-winapi-x86-64-pc-windows-gnu-dev:armhf (0.4.0-1) ... 433s Setting up libcc1-0:armhf (14.2.0-9ubuntu1) ... 433s Setting up libbrotli-dev:armhf (1.1.0-2build3) ... 433s Setting up librust-clap-lex-dev:armhf (0.7.2-2) ... 433s Setting up libhttp-parser2.9:armhf (2.9.4-6build1) ... 433s Setting up librust-unarray-dev:armhf (0.1.4-1) ... 433s Setting up cpp-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 433s Setting up libllvm18:armhf (1:18.1.8-12) ... 433s Setting up librust-itertools-dev:armhf (0.10.5-1) ... 433s Setting up librust-heck-dev:armhf (0.4.1-1) ... 433s Setting up librust-num-conv-dev:armhf (0.1.0-1) ... 433s Setting up libpython3.13:armhf (3.13.0-2) ... 433s Setting up automake (1:1.16.5-1.3ubuntu1) ... 434s update-alternatives: using /usr/bin/automake-1.16 to provide /usr/bin/automake (automake) in auto mode 434s Setting up libfile-stripnondeterminism-perl (1.14.0-1) ... 434s Setting up librust-owned-ttf-parser-dev:armhf (0.24.0-1) ... 434s Setting up librust-crossbeam-epoch+std-dev:armhf (0.9.18-1) ... 434s Setting up librust-libc-dev:armhf (0.2.161-1) ... 434s Setting up librust-is-terminal-dev:armhf (0.4.13-1) ... 434s Setting up gettext (0.22.5-2) ... 434s Setting up librust-gif-dev:armhf (0.11.3-1) ... 434s Setting up librust-crossbeam-deque-dev:armhf (0.8.5-1) ... 434s Setting up librust-tiny-keccak-dev:armhf (2.0.2-1) ... 434s Setting up python3.13 (3.13.0-2) ... 435s Setting up librust-linux-raw-sys-dev:armhf (0.4.14-1) ... 435s Setting up pybuild-plugin-pyproject (6.20241024) ... 435s Setting up fontconfig-config (2.15.0-1.1ubuntu2) ... 435s Setting up librust-getrandom-dev:armhf (0.2.12-1) ... 435s Setting up python3-pytest (8.3.3-1) ... 436s Setting up librust-libloading-dev:armhf (0.8.5-1) ... 436s Setting up librust-socket2-dev:armhf (0.5.7-1) ... 436s Setting up librust-memmap2-dev:armhf (0.9.3-1) ... 436s Setting up libwebpdemux2:armhf (1.4.0-0.1) ... 436s Setting up python3-hypothesis (6.119.3-1) ... 437s Setting up librust-ab-glyph-rasterizer+libm-dev:armhf (0.1.7-1) ... 437s Setting up librust-tinyvec+tinyvec-macros-dev:armhf (1.6.0-2) ... 437s Setting up librust-owning-ref-dev:armhf (0.4.1-1) ... 437s Setting up librust-num-cpus-dev:armhf (1.16.0-1) ... 437s Setting up librust-memoffset-dev:armhf (0.8.0-1) ... 437s Setting up gcc-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 437s Setting up python3-all (3.12.7-1) ... 437s Setting up librust-cpufeatures-dev:armhf (0.2.11-1) ... 437s Setting up librust-proc-macro2-dev:armhf (1.0.86-1) ... 437s Setting up librust-compiler-builtins+rustc-dep-of-std-dev:armhf (0.1.101-1) ... 437s Setting up librust-rayon-core-dev:armhf (1.12.1-1) ... 437s Setting up librust-winapi-dev:armhf (0.3.9-1) ... 437s Setting up pkgconf:armhf (1.8.1-4) ... 437s Setting up librust-ab-glyph-dev:armhf (0.2.28-1) ... 437s Setting up intltool-debian (0.35.0+20060710.6) ... 437s Setting up librust-rand-core+getrandom-dev:armhf (0.6.4-2) ... 437s Setting up librust-rand-xorshift-dev:armhf (0.3.0-2) ... 437s Setting up librust-signal-hook-registry-dev:armhf (1.4.0-1) ... 437s Setting up libwebp-dev:armhf (1.4.0-0.1) ... 437s Setting up librust-errno-dev:armhf (0.3.8-1) ... 437s Setting up librust-anes-dev:armhf (0.1.6-1) ... 437s Setting up llvm-runtime:armhf (1:19.0-60~exp1) ... 437s Setting up librust-jobserver-dev:armhf (0.1.32-1) ... 437s Setting up pkg-config:armhf (1.8.1-4) ... 437s Setting up cpp-14 (14.2.0-9ubuntu1) ... 437s Setting up dh-strip-nondeterminism (1.14.0-1) ... 437s Setting up librust-crc32fast-dev:armhf (1.4.2-1) ... 437s Setting up librust-num-traits-dev:armhf (0.2.19-2) ... 437s Setting up librust-winapi-util-dev:armhf (0.1.6-1) ... 437s Setting up librust-wait-timeout-dev:armhf (0.2.0-1) ... 437s Setting up cmake (3.30.3-1) ... 437s Setting up libgit2-1.7:armhf (1.7.2+ds-1ubuntu3) ... 437s Setting up libc6-dev:armhf (2.40-1ubuntu3) ... 437s Setting up llvm-19 (1:19.1.2-1ubuntu1) ... 437s Setting up librust-same-file-dev:armhf (1.0.6-1) ... 437s Setting up librust-rayon-dev:armhf (1.10.0-1) ... 437s Setting up librust-termcolor-dev:armhf (1.4.1-1) ... 437s Setting up librust-pkg-config-dev:armhf (0.3.27-1) ... 437s Setting up libstdc++-14-dev:armhf (14.2.0-9ubuntu1) ... 437s Setting up cpp-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 437s Setting up libstd-rust-1.80:armhf (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 437s Setting up librust-jpeg-decoder-dev:armhf (0.3.0-1) ... 437s Setting up libbz2-dev:armhf (1.0.8-6) ... 437s Setting up librust-dirs-sys-next-dev:armhf (0.1.1-1) ... 437s Setting up gcc-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 437s Setting up librust-num-integer-dev:armhf (0.1.46-1) ... 437s Setting up librust-dirs-next-dev:armhf (2.0.0-1) ... 437s Setting up librust-num-threads-dev:armhf (0.1.7-1) ... 437s Setting up g++-14-arm-linux-gnueabihf (14.2.0-9ubuntu1) ... 437s Setting up librust-dlib-dev:armhf (0.5.2-2) ... 437s Setting up librust-libwebp-sys-dev:armhf (0.9.5-1build1) ... 437s Setting up po-debconf (1.0.21+nmu1) ... 437s Setting up librust-quote-dev:armhf (1.0.37-1) ... 437s Setting up librust-syn-dev:armhf (2.0.85-1) ... 437s Setting up librust-rand-core+std-dev:armhf (0.6.4-2) ... 437s Setting up librust-powerfmt-macros-dev:armhf (0.1.0-1) ... 437s Setting up gcc-14 (14.2.0-9ubuntu1) ... 437s Setting up libstd-rust-1.80-dev:armhf (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 437s Setting up libexpat1-dev:armhf (2.6.4-1) ... 437s Setting up librust-powerfmt-dev:armhf (0.2.0-1) ... 438s Setting up librust-sval-derive-dev:armhf (2.6.1-2) ... 438s Setting up uuid-dev:armhf (2.40.2-1ubuntu1) ... 438s Setting up librust-cc-dev:armhf (1.1.14-1) ... 438s Setting up librust-zeroize-derive-dev:armhf (1.4.2-1) ... 438s Setting up llvm (1:19.0-60~exp1) ... 438s Setting up librust-postgres-derive-dev:armhf (0.4.5-1) ... 438s Setting up librust-syn-1-dev:armhf (1.0.109-3) ... 438s Setting up librust-clap-derive-dev:armhf (4.5.13-2) ... 438s Setting up zlib1g-dev:armhf (1:1.3.dfsg+really1.3.1-1ubuntu1) ... 438s Setting up librust-bytecheck-derive-dev:armhf (0.6.12-1) ... 438s Setting up librust-no-panic-dev:armhf (0.1.13-1) ... 438s Setting up cpp (4:14.1.0-2ubuntu1) ... 438s Setting up librust-serde-derive-dev:armhf (1.0.210-1) ... 438s Setting up librust-walkdir-dev:armhf (2.5.0-1) ... 438s Setting up librust-zerocopy-derive-dev:armhf (0.7.32-2) ... 438s Setting up librust-sha1-asm-dev:armhf (0.5.1-2) ... 438s Setting up g++-14 (14.2.0-9ubuntu1) ... 438s Setting up librust-valuable-derive-dev:armhf (0.1.0-1) ... 438s Setting up librust-ghost-dev:armhf (0.1.5-1) ... 438s Setting up librust-serde-dev:armhf (1.0.210-2) ... 438s Setting up librust-bytemuck-derive-dev:armhf (1.5.0-2) ... 438s Setting up librust-derive-arbitrary-dev:armhf (1.3.2-1) ... 438s Setting up librust-allocator-api2-dev:armhf (0.2.16-1) ... 438s Setting up librust-cmake-dev:armhf (0.1.45-1) ... 438s Setting up g++-arm-linux-gnueabihf (4:14.1.0-2ubuntu1) ... 438s Setting up librust-async-attributes-dev (1.1.2-6) ... 438s Setting up librust-rand-chacha-dev:armhf (0.3.1-2) ... 438s Setting up librust-futures-macro-dev:armhf (0.3.30-1) ... 438s Setting up librust-ctor-dev:armhf (0.1.26-1) ... 438s Setting up librust-unicode-bidi-dev:armhf (0.3.13-1) ... 438s Setting up librust-tracing-attributes-dev:armhf (0.1.27-1) ... 438s Setting up librust-ptr-meta-derive-dev:armhf (0.1.4-1) ... 438s Setting up librust-serde-fmt-dev (1.0.3-3) ... 438s Setting up libtool (2.4.7-8) ... 438s Setting up librust-sha2-asm-dev:armhf (0.6.2-2) ... 438s Setting up libpng-dev:armhf (1.6.44-2) ... 438s Setting up librust-portable-atomic-dev:armhf (1.9.0-4) ... 438s Setting up librust-tokio-macros-dev:armhf (2.4.0-2) ... 438s Setting up librust-lock-api-dev:armhf (0.4.12-1) ... 438s Setting up librust-libz-sys-dev:armhf (1.1.20-1) ... 438s Setting up libpython3.12-dev:armhf (3.12.7-3) ... 438s Setting up librust-ptr-meta-dev:armhf (0.1.4-1) ... 438s Setting up librust-inventory-dev:armhf (0.3.2-1) ... 438s Setting up librust-sval-dev:armhf (2.6.1-2) ... 438s Setting up librust-itoa-dev:armhf (1.0.9-1) ... 438s Setting up gcc (4:14.1.0-2ubuntu1) ... 438s Setting up librust-bytes-dev:armhf (1.8.0-1) ... 438s Setting up librust-bumpalo-dev:armhf (3.16.0-1) ... 438s Setting up librust-python3-dll-a-dev:armhf (0.2.10-1) ... 438s Setting up libfreetype-dev:armhf (2.13.3+dfsg-1) ... 438s Setting up librust-siphasher-dev:armhf (0.3.10-1) ... 438s Setting up rustc-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 438s Setting up dh-autoreconf (20) ... 438s Setting up librust-rand-core+serde-dev:armhf (0.6.4-2) ... 438s Setting up librust-sval-ref-dev:armhf (2.6.1-1) ... 438s Setting up librust-rkyv-derive-dev:armhf (0.7.44-1) ... 438s Setting up libpython3.13-dev:armhf (3.13.0-2) ... 438s Setting up librust-zerocopy-dev:armhf (0.7.32-1) ... 438s Setting up librust-md5-asm-dev:armhf (0.5.0-2) ... 438s Setting up librust-semver-dev:armhf (1.0.23-1) ... 438s Setting up python3.12-dev (3.12.7-3) ... 438s Setting up librust-bytemuck-dev:armhf (1.14.0-1) ... 438s Setting up librust-bit-vec-dev:armhf (0.6.3-1) ... 438s Setting up librust-zeroize-dev:armhf (1.8.1-1) ... 438s Setting up librust-slab-dev:armhf (0.4.9-1) ... 438s Setting up g++ (4:14.1.0-2ubuntu1) ... 438s update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode 438s Setting up rustc (1.80.1ubuntu2) ... 438s Setting up librust-arbitrary-dev:armhf (1.3.2-1) ... 438s Setting up librust-valuable-dev:armhf (0.1.0-4) ... 438s Setting up librust-target-lexicon-dev:armhf (0.12.14-1) ... 438s Setting up librust-serde-test-dev:armhf (1.0.171-1) ... 438s Setting up librust-bit-set-dev:armhf (0.5.2-1) ... 438s Setting up build-essential (12.10ubuntu1) ... 438s Setting up librust-concurrent-queue-dev:armhf (2.5.0-4) ... 438s Setting up cargo-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 438s Setting up librust-erased-serde-dev:armhf (0.3.31-1) ... 438s Setting up librust-radium-dev:armhf (1.1.0-1) ... 438s Setting up librust-bit-set+std-dev:armhf (0.5.2-1) ... 438s Setting up librust-phf-shared-dev:armhf (0.11.2-1) ... 438s Setting up librust-smol-str-dev:armhf (0.2.0-1) ... 438s Setting up librust-atomic-dev:armhf (0.6.0-1) ... 438s Setting up librust-generic-array-dev:armhf (0.14.7-1) ... 438s Setting up librust-half-dev:armhf (1.8.2-4) ... 438s Setting up librust-phf-dev:armhf (0.11.2-1) ... 438s Setting up librust-spin-dev:armhf (0.9.8-4) ... 438s Setting up libpython3-dev:armhf (3.12.7-1) ... 438s Setting up librust-sval-dynamic-dev:armhf (2.6.1-1) ... 438s Setting up librust-qoi-dev:armhf (0.4.1-2) ... 438s Setting up librust-async-task-dev (4.7.1-3) ... 438s Setting up librust-crypto-common-dev:armhf (0.1.6-1) ... 438s Setting up librust-ciborium-ll-dev:armhf (0.2.2-1) ... 438s Setting up librust-futures-core-dev:armhf (0.3.30-1) ... 438s Setting up librust-lazy-static-dev:armhf (1.5.0-1) ... 438s Setting up librust-sval-buffer-dev:armhf (2.6.1-1) ... 438s Setting up librust-arrayvec-dev:armhf (0.7.4-2) ... 438s Setting up librust-rustc-version-dev:armhf (0.4.0-1) ... 438s Setting up librust-event-listener-dev (5.3.1-8) ... 438s Setting up librust-flate2-dev:armhf (1.0.34-1) ... 438s Setting up librust-freetype-sys-dev:armhf (0.13.1-1) ... 438s Setting up debhelper (13.20ubuntu1) ... 438s Setting up librust-smallvec-dev:armhf (1.13.2-1) ... 438s Setting up librust-sval-fmt-dev:armhf (2.6.1-1) ... 438s Setting up librust-const-oid-dev:armhf (0.9.3-1) ... 438s Setting up librust-anstyle-parse-dev:armhf (0.2.1-1) ... 438s Setting up cargo (1.80.1ubuntu2) ... 438s Setting up librust-ciborium-dev:armhf (0.2.2-2) ... 438s Setting up librust-block-buffer-dev:armhf (0.10.2-2) ... 438s Setting up python3-setuptools-rust (1.9.0+dfsg-2) ... 438s Setting up libpython3-all-dev:armhf (3.12.7-1) ... 438s Setting up librust-pathfinder-simd-dev:armhf (0.5.2-1) ... 438s Setting up librust-freetype-dev:armhf (0.7.0-4) ... 438s Setting up librust-unicode-normalization-dev:armhf (0.1.22-1) ... 438s Setting up librust-anstream-dev:armhf (0.6.15-1) ... 438s Setting up librust-bitflags-dev:armhf (2.6.0-1) ... 438s Setting up librust-regex-syntax-dev:armhf (0.8.5-1) ... 438s Setting up librust-parking-lot-core-dev:armhf (0.9.10-1) ... 438s Setting up librust-futures-channel-dev:armhf (0.3.30-1) ... 438s Setting up librust-once-cell-dev:armhf (1.20.2-1) ... 438s Setting up librust-pyo3-build-config-dev:armhf (0.22.6-1) ... 438s Setting up librust-phf-shared+uncased-dev:armhf (0.11.2-1) ... 438s Setting up librust-tiff-dev:armhf (0.9.0-1) ... 438s Setting up librust-digest-dev:armhf (0.10.7-2) ... 438s Setting up librust-md-5-dev:armhf (0.10.6-1) ... 438s Setting up librust-sval-serde-dev:armhf (2.6.1-1) ... 438s Setting up librust-parking-lot-dev:armhf (0.12.3-1) ... 438s Setting up librust-event-listener-strategy-dev:armhf (0.5.2-3) ... 438s Setting up librust-pyo3-macros-backend-dev:armhf (0.22.6-1) ... 438s Setting up librust-pyo3-ffi-dev:armhf (0.22.6-1build1) ... 438s Setting up librust-png-dev:armhf (0.17.7-3) ... 438s Setting up pybuild-plugin-autopkgtest (6.20241024) ... 438s Setting up librust-const-random-macro-dev:armhf (0.1.16-2) ... 438s Setting up librust-const-random-dev:armhf (0.1.17-2) ... 438s Setting up librust-pyo3-macros-dev:armhf (0.22.6-1) ... 438s Setting up librust-sha1-dev:armhf (0.10.6-1) ... 438s Setting up librust-ahash-dev (0.8.11-8) ... 438s Setting up librust-async-channel-dev (2.3.1-8) ... 438s Setting up librust-stringprep-dev:armhf (0.1.2-1) ... 438s Setting up librust-tracing-core-dev:armhf (0.1.32-1) ... 438s Setting up librust-async-lock-dev (3.4.0-4) ... 438s Setting up librust-eyre-dev:armhf (0.6.12-1) ... 438s Setting up librust-sha2-dev:armhf (0.10.8-1) ... 438s Setting up librust-hmac-dev:armhf (0.12.1-1) ... 438s Setting up librust-rustix-dev:armhf (0.38.37-1) ... 438s Setting up librust-wyz-dev:armhf (0.5.1-1) ... 438s Setting up librust-bitvec-dev:armhf (1.0.1-1) ... 438s Setting up librust-phf+uncased-dev:armhf (0.11.2-1) ... 438s Setting up librust-value-bag-sval2-dev:armhf (1.9.0-1) ... 438s Setting up librust-tempfile-dev:armhf (3.13.0-1) ... 438s Setting up librust-eyre+default-dev:armhf (0.6.12-1) ... 438s Setting up librust-rusty-fork-dev:armhf (0.3.0-1) ... 438s Setting up librust-hashbrown-dev:armhf (0.14.5-5) ... 438s Setting up librust-rusty-fork+wait-timeout-dev:armhf (0.3.0-1) ... 438s Setting up librust-terminal-size-dev:armhf (0.3.0-2) ... 438s Setting up librust-indexmap-dev:armhf (2.2.6-1) ... 438s Setting up librust-gimli-dev:armhf (0.28.1-2) ... 438s Setting up librust-webp-dev:armhf (0.2.6-1) ... 438s Setting up librust-memchr-dev:armhf (2.7.4-1) ... 438s Setting up librust-futures-util-dev:armhf (0.3.30-2) ... 438s Setting up librust-csv-core-dev:armhf (0.1.11-1) ... 438s Setting up librust-futures-lite-dev:armhf (2.3.0-2) ... 438s Setting up librust-csv-dev:armhf (1.3.0-1) ... 438s Setting up librust-serde-json-dev:armhf (1.0.128-1) ... 438s Setting up librust-async-executor-dev (1.13.1-1) ... 439s Setting up librust-futures-executor-dev:armhf (0.3.30-1) ... 439s Setting up librust-value-bag-serde1-dev:armhf (1.9.0-1) ... 439s Setting up librust-tinytemplate-dev:armhf (1.2.1-1) ... 439s Setting up librust-futures-dev:armhf (0.3.30-2) ... 439s Setting up librust-value-bag-dev:armhf (1.9.0-1) ... 439s Setting up librust-log-dev:armhf (0.4.22-1) ... 439s Setting up librust-kv-log-macro-dev (1.0.8-4) ... 439s Setting up librust-pathfinder-geometry-dev:armhf (0.5.1-1) ... 439s Setting up librust-tracing-dev:armhf (0.1.40-1) ... 439s Setting up librust-polling-dev:armhf (3.4.0-1) ... 439s Setting up librust-aho-corasick-dev:armhf (1.1.3-1) ... 439s Setting up librust-async-io-dev:armhf (2.3.3-4) ... 439s Setting up librust-blocking-dev (1.6.1-5) ... 439s Setting up librust-async-net-dev (2.0.0-4) ... 439s Setting up librust-rand-dev:armhf (0.8.5-1) ... 439s Setting up librust-mio-dev:armhf (1.0.2-2) ... 439s Setting up librust-wasm-bindgen-backend-dev:armhf (0.2.87-1) ... 439s Setting up librust-twox-hash-dev:armhf (1.6.3-1) ... 439s Setting up librust-proptest-dev:armhf (1.5.0-2) ... 439s Setting up librust-wasm-bindgen-macro-support-dev:armhf (0.2.87-1) ... 439s Setting up librust-regex-automata-dev:armhf (0.4.9-1) ... 439s Setting up librust-wasm-bindgen-macro-support+spans-dev:armhf (0.2.87-1) ... 439s Setting up librust-wasm-bindgen-macro-dev:armhf (0.2.87-1) ... 439s Setting up librust-uuid-dev:armhf (1.10.0-1) ... 439s Setting up librust-bstr-dev:armhf (1.7.0-2build1) ... 439s Setting up librust-async-signal-dev:armhf (0.2.10-1) ... 439s Setting up librust-bytecheck-dev:armhf (0.6.12-1) ... 439s Setting up librust-postgres-protocol-dev:armhf (0.6.6-2) ... 439s Setting up librust-async-fs-dev (2.1.2-4) ... 439s Setting up librust-wasm-bindgen-dev:armhf (0.2.87-1) ... 439s Setting up librust-convert-case-dev:armhf (0.6.0-2) ... 439s Setting up librust-regex-dev:armhf (1.10.6-1) ... 439s Setting up librust-fancy-regex-dev:armhf (0.11.0-2) ... 439s Setting up librust-async-process-dev (2.3.0-1) ... 439s Setting up librust-wasm-bindgen-macro+spans-dev:armhf (0.2.87-1) ... 439s Setting up librust-rend-dev:armhf (0.4.0-1) ... 439s Setting up librust-derive-more-0.99-dev:armhf (0.99.18-2) ... 439s Setting up librust-env-logger-dev:armhf (0.10.2-2) ... 439s Setting up librust-wasm-bindgen+spans-dev:armhf (0.2.87-1) ... 439s Setting up librust-wasm-bindgen+default-dev:armhf (0.2.87-1) ... 439s Setting up librust-rkyv-dev:armhf (0.7.44-1) ... 439s Setting up librust-eui48-dev:armhf (1.1.0-2) ... 439s Setting up librust-parse-zoneinfo-dev:armhf (0.3.0-1) ... 439s Setting up librust-smol-dev (2.0.2-1) ... 439s Setting up librust-js-sys-dev:armhf (0.3.64-1) ... 439s Setting up librust-num-complex-dev:armhf (0.4.6-2) ... 439s Setting up librust-approx-dev:armhf (0.5.1-1) ... 439s Setting up librust-ruzstd-dev:armhf (0.5.0-1) ... 439s Setting up librust-web-sys-dev:armhf (0.3.64-2) ... 439s Setting up librust-quickcheck-dev:armhf (1.0.3-3) ... 439s Setting up librust-geo-types-dev:armhf (0.7.11-2) ... 439s Setting up librust-deranged-dev:armhf (0.3.11-1) ... 439s Setting up librust-num-bigint-dev:armhf (0.4.6-1) ... 439s Setting up librust-num-rational-dev:armhf (0.4.2-1) ... 439s Setting up librust-chrono-dev:armhf (0.4.38-2) ... 439s Setting up librust-object-dev:armhf (0.32.2-1) ... 439s Setting up librust-image-dev:armhf (0.24.7-2) ... 439s Setting up librust-time-dev:armhf (0.3.36-2) ... 439s Setting up librust-plotters-bitmap-dev:armhf (0.3.3-3) ... 439s Setting up librust-postgres-types-dev:armhf (0.2.6-2) ... 439s Setting up librust-addr2line-dev:armhf (0.21.0-2) ... 439s Setting up librust-plotters-svg-dev:armhf (0.3.5-1) ... 439s Setting up librust-rust-decimal-dev:armhf (1.36.0-1) ... 439s Setting up librust-backtrace-dev:armhf (0.3.69-2) ... 439s Setting up librust-tokio-dev:armhf (1.39.3-3) ... 439s Setting up librust-async-global-executor-dev:armhf (2.4.1-5) ... 439s Setting up librust-clap-builder-dev:armhf (4.5.15-2) ... 439s Setting up librust-clap-dev:armhf (4.5.16-1) ... 439s Setting up librust-async-std-dev (1.13.0-1) ... 439s Setting up librust-anyhow-dev:armhf (1.0.86-1) ... 440s Processing triggers for sgml-base (1.31) ... 440s Setting up libfontconfig1:armhf (2.15.0-1.1ubuntu2) ... 440s Processing triggers for install-info (7.1.1-1) ... 440s Setting up libfontconfig-dev:armhf (2.15.0-1.1ubuntu2) ... 440s Processing triggers for libc-bin (2.40-1ubuntu3) ... 440s Processing triggers for systemd (256.5-2ubuntu4) ... 440s Processing triggers for man-db (2.13.0-1) ... 441s Setting up librust-yeslogic-fontconfig-sys-dev:armhf (3.0.1-1) ... 441s Setting up librust-font-kit-dev:armhf (0.11.0-2) ... 441s Setting up librust-plotters-dev:armhf (0.3.5-4) ... 441s Setting up librust-criterion-dev (0.5.1-6) ... 441s Setting up librust-phf-generator-dev:armhf (0.11.2-2) ... 441s Setting up librust-phf-codegen-dev:armhf (0.11.2-1) ... 441s Setting up librust-chrono-tz-build-dev:armhf (0.2.1-1) ... 441s Setting up librust-chrono-tz-dev:armhf (0.8.6-2) ... 441s Setting up librust-pyo3-dev:armhf (0.22.6-1) ... 453s autopkgtest [09:42:30]: test pybuild-autopkgtest: pybuild-autopkgtest 453s autopkgtest [09:42:30]: test pybuild-autopkgtest: [----------------------- 456s pybuild-autopkgtest 456s I: pybuild base:311: cd /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build; python3.13 -m pytest tests 457s ============================= test session starts ============================== 457s platform linux -- Python 3.13.0, pytest-8.3.3, pluggy-1.5.0 457s rootdir: /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build 457s configfile: pyproject.toml 457s plugins: typeguard-4.4.1, hypothesis-6.119.3 457s collected 30 items 457s 1034s tests/test_encoding.py FFFFFFFFFFFFFFFFFFFFFF [ 73%] 1036s tests/test_misc.py F. [ 80%] 1038s tests/test_offsets.py FF [ 86%] 1039s tests/test_pickle.py F [ 90%] 1041s tests/test_simple_public.py FF. [100%] 1041s 1041s =================================== FAILURES =================================== 1041s _________________________________ test_simple __________________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_simple(): 1041s > enc = tiktoken.get_encoding("gpt2") 1041s 1041s tests/test_encoding.py:15: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1041s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1041s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _____________________________ test_simple_repeated _____________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_simple_repeated(): 1041s > enc = tiktoken.get_encoding("gpt2") 1041s 1041s tests/test_encoding.py:32: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1041s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1041s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_simple_regex _______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_simple_regex(): 1041s > enc = tiktoken.get_encoding("cl100k_base") 1041s 1041s tests/test_encoding.py:53: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_basic_encode _______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_basic_encode(): 1041s > enc = tiktoken.get_encoding("r50k_base") 1041s 1041s tests/test_encoding.py:62: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_encode_empty _______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_encode_empty(): 1041s > enc = tiktoken.get_encoding("r50k_base") 1041s 1041s tests/test_encoding.py:74: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_encode_bytes _______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_encode_bytes(): 1041s > enc = tiktoken.get_encoding("cl100k_base") 1041s 1041s tests/test_encoding.py:79: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _________________________ test_encode_surrogate_pairs __________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_encode_surrogate_pairs(): 1041s > enc = tiktoken.get_encoding("cl100k_base") 1041s 1041s tests/test_encoding.py:84: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _________________ test_catastrophically_repetitive[r50k_base] __________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:96: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ________________ test_catastrophically_repetitive[cl100k_base] _________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:96: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _______________________ test_basic_roundtrip[r50k_base] ________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_basic_roundtrip(make_enc): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:115: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________ test_basic_roundtrip[cl100k_base] _______________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_basic_roundtrip(make_enc): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:115: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ________________________ test_hyp_roundtrip[r50k_base] _________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(text=st.text()) 1041s 1041s tests/test_encoding.py:131: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:134: in test_hyp_roundtrip 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_roundtrip( 1041s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1041s E text='', # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _______________________ test_hyp_roundtrip[cl100k_base] ________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(text=st.text()) 1041s 1041s tests/test_encoding.py:131: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:134: in test_hyp_roundtrip 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_roundtrip( 1041s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1041s E text='', # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ____________________ test_single_token_roundtrip[r50k_base] ____________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:141: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ___________________ test_single_token_roundtrip[cl100k_base] ___________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:141: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_special_token ______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_special_token(): 1041s > enc = tiktoken.get_encoding("cl100k_base") 1041s 1041s tests/test_encoding.py:157: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _____________________ test_hyp_special_ordinary[r50k_base] _____________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(text=st.text()) 1041s 1041s tests/test_encoding.py:208: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:211: in test_hyp_special_ordinary 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_special_ordinary( 1041s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1041s E text='', # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ____________________ test_hyp_special_ordinary[cl100k_base] ____________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(text=st.text()) 1041s 1041s tests/test_encoding.py:208: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:211: in test_hyp_special_ordinary 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_special_ordinary( 1041s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1041s E text='', # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _________________________ test_batch_encode[r50k_base] _________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:222: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ________________________ test_batch_encode[cl100k_base] ________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 1041s > enc = make_enc() 1041s 1041s tests/test_encoding.py:222: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s _____________________ test_hyp_batch_roundtrip[r50k_base] ______________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s E: pybuild pybuild:389: test: plugin pyproject failed with: exit code=1: cd /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build; python3.13 -m pytest tests 1041s I: pybuild base:311: cd /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build; python3.12 -m pytest tests 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'r50k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(batch=st.lists(st.text())) 1041s 1041s tests/test_encoding.py:237: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_batch_roundtrip( 1041s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1041s E batch=[], # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ____________________ test_hyp_batch_roundtrip[cl100k_base] _____________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1041s > @hypothesis.given(batch=st.lists(st.text())) 1041s 1041s tests/test_encoding.py:237: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_batch_roundtrip( 1041s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1041s E batch=[], # or any other generated value 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ___________________________ test_encoding_for_model ____________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s def test_encoding_for_model(): 1041s > enc = tiktoken.encoding_for_model("gpt2") 1041s 1041s tests/test_misc.py:8: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 1041s return get_encoding(encoding_name_for_model(model_name)) 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1041s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1041s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ________________________ test_hyp_offsets[cl100k_base] _________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s > resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1041s retries = retries.increment( 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1041s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1041s _pool = 1041s _stacktrace = 1041s 1041s def increment( 1041s self, 1041s method: str | None = None, 1041s url: str | None = None, 1041s response: BaseHTTPResponse | None = None, 1041s error: Exception | None = None, 1041s _pool: ConnectionPool | None = None, 1041s _stacktrace: TracebackType | None = None, 1041s ) -> Retry: 1041s """Return a new Retry object with incremented retry counters. 1041s 1041s :param response: A response object, or None, if the server did not 1041s return a response. 1041s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1041s :param Exception error: An error encountered during the request, or 1041s None if the response was received successfully. 1041s 1041s :return: A new ``Retry`` object. 1041s """ 1041s if self.total is False and error: 1041s # Disabled, indicate to re-raise the error. 1041s raise reraise(type(error), error, _stacktrace) 1041s 1041s total = self.total 1041s if total is not None: 1041s total -= 1 1041s 1041s connect = self.connect 1041s read = self.read 1041s redirect = self.redirect 1041s status_count = self.status 1041s other = self.other 1041s cause = "unknown" 1041s status = None 1041s redirect_location = None 1041s 1041s if error and self._is_connection_error(error): 1041s # Connect retry? 1041s if connect is False: 1041s raise reraise(type(error), error, _stacktrace) 1041s elif connect is not None: 1041s connect -= 1 1041s 1041s elif error and self._is_read_error(error): 1041s # Read retry? 1041s if read is False or method is None or not self._is_method_retryable(method): 1041s raise reraise(type(error), error, _stacktrace) 1041s elif read is not None: 1041s read -= 1 1041s 1041s elif error: 1041s # Other retry? 1041s if other is not None: 1041s other -= 1 1041s 1041s elif response and response.get_redirect_location(): 1041s # Redirect retry? 1041s if redirect is not None: 1041s redirect -= 1 1041s cause = "too many redirects" 1041s response_redirect_location = response.get_redirect_location() 1041s if response_redirect_location: 1041s redirect_location = response_redirect_location 1041s status = response.status 1041s 1041s else: 1041s # Incrementing because of a server error like a 500 in 1041s # status_forcelist and the given method is in the allowed_methods 1041s cause = ResponseError.GENERIC_ERROR 1041s if response and response.status: 1041s if status_count is not None: 1041s status_count -= 1 1041s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1041s status = response.status 1041s 1041s history = self.history + ( 1041s RequestHistory(method, url, error, status, redirect_location), 1041s ) 1041s 1041s new_retry = self.new( 1041s total=total, 1041s connect=connect, 1041s read=read, 1041s redirect=redirect, 1041s status=status_count, 1041s other=other, 1041s history=history, 1041s ) 1041s 1041s if new_retry.is_exhausted(): 1041s reason = error or ResponseError(cause) 1041s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1041s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1041s 1041s During handling of the above exception, another exception occurred: 1041s 1041s make_enc = functools.partial(, 'cl100k_base') 1041s 1041s @pytest.mark.parametrize("make_enc", SOME_ENCODING_FACTORIES) 1041s > @hypothesis.given(data=st.data()) 1041s 1041s tests/test_offsets.py:29: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s tests/test_offsets.py:32: in test_hyp_offsets 1041s enc = make_enc() 1041s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1041s enc = Encoding(**constructor()) 1041s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1041s mergeable_ranks = load_tiktoken_bpe( 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1041s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1041s contents = read_file(blobpath) 1041s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1041s resp = requests.get(blobpath) 1041s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1041s return request("get", url, params=params, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1041s return session.request(method=method, url=url, **kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1041s resp = self.send(prep, **send_kwargs) 1041s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1041s r = adapter.send(request, **kwargs) 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1041s stream=stream, 1041s timeout=timeout, 1041s verify=verify, 1041s cert=cert, 1041s proxies=proxies, 1041s ) 1041s 1041s chunked = not (request.body is None or "Content-Length" in request.headers) 1041s 1041s if isinstance(timeout, tuple): 1041s try: 1041s connect, read = timeout 1041s timeout = TimeoutSauce(connect=connect, read=read) 1041s except ValueError: 1041s raise ValueError( 1041s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1041s f"or a single float to set both timeouts to the same value." 1041s ) 1041s elif isinstance(timeout, TimeoutSauce): 1041s pass 1041s else: 1041s timeout = TimeoutSauce(connect=timeout, read=timeout) 1041s 1041s try: 1041s resp = conn.urlopen( 1041s method=request.method, 1041s url=url, 1041s body=request.body, 1041s headers=request.headers, 1041s redirect=False, 1041s assert_same_host=False, 1041s preload_content=False, 1041s decode_content=False, 1041s retries=self.max_retries, 1041s timeout=timeout, 1041s chunked=chunked, 1041s ) 1041s 1041s except (ProtocolError, OSError) as err: 1041s raise ConnectionError(err, request=request) 1041s 1041s except MaxRetryError as e: 1041s if isinstance(e.reason, ConnectTimeoutError): 1041s # TODO: Remove this in 3.0.0: see #2811 1041s if not isinstance(e.reason, NewConnectionError): 1041s raise ConnectTimeout(e, request=request) 1041s 1041s if isinstance(e.reason, ResponseError): 1041s raise RetryError(e, request=request) 1041s 1041s if isinstance(e.reason, _ProxyError): 1041s raise ProxyError(e, request=request) 1041s 1041s if isinstance(e.reason, _SSLError): 1041s # This branch is for urllib3 v1.22 and later. 1041s raise SSLError(e, request=request) 1041s 1041s > raise ConnectionError(e, request=request) 1041s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1041s E Falsifying example: test_hyp_offsets( 1041s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1041s E data=data(...), 1041s E ) 1041s 1041s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1041s ______________________________ test_basic_offsets ______________________________ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s > sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1041s raise err 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1041s source_address = None, socket_options = [(6, 1, 1)] 1041s 1041s def create_connection( 1041s address: tuple[str, int], 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s source_address: tuple[str, int] | None = None, 1041s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1041s ) -> socket.socket: 1041s """Connect to *address* and return the socket object. 1041s 1041s Convenience function. Connect to *address* (a 2-tuple ``(host, 1041s port)``) and return the socket object. Passing the optional 1041s *timeout* parameter will set the timeout on the socket instance 1041s before attempting to connect. If no *timeout* is supplied, the 1041s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1041s is used. If *source_address* is set it must be a tuple of (host, port) 1041s for the socket to bind as a source address before making the connection. 1041s An host of '' or port 0 tells the OS to use the default. 1041s """ 1041s 1041s host, port = address 1041s if host.startswith("["): 1041s host = host.strip("[]") 1041s err = None 1041s 1041s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1041s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1041s # The original create_connection function always returns all records. 1041s family = allowed_gai_family() 1041s 1041s try: 1041s host.encode("idna") 1041s except UnicodeError: 1041s raise LocationParseError(f"'{host}', label empty or too long") from None 1041s 1041s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1041s af, socktype, proto, canonname, sa = res 1041s sock = None 1041s try: 1041s sock = socket.socket(af, socktype, proto) 1041s 1041s # If provided, set socket level options before connecting. 1041s _set_socket_options(sock, socket_options) 1041s 1041s if timeout is not _DEFAULT_TIMEOUT: 1041s sock.settimeout(timeout) 1041s if source_address: 1041s sock.bind(source_address) 1041s > sock.connect(sa) 1041s E ConnectionRefusedError: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1041s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1041s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1041s redirect = False, assert_same_host = False 1041s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1041s release_conn = False, chunked = False, body_pos = None, preload_content = False 1041s decode_content = False, response_kw = {} 1041s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1041s destination_scheme = None, conn = None, release_this_conn = True 1041s http_tunnel_required = False, err = None, clean_exit = False 1041s 1041s def urlopen( # type: ignore[override] 1041s self, 1041s method: str, 1041s url: str, 1041s body: _TYPE_BODY | None = None, 1041s headers: typing.Mapping[str, str] | None = None, 1041s retries: Retry | bool | int | None = None, 1041s redirect: bool = True, 1041s assert_same_host: bool = True, 1041s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1041s pool_timeout: int | None = None, 1041s release_conn: bool | None = None, 1041s chunked: bool = False, 1041s body_pos: _TYPE_BODY_POSITION | None = None, 1041s preload_content: bool = True, 1041s decode_content: bool = True, 1041s **response_kw: typing.Any, 1041s ) -> BaseHTTPResponse: 1041s """ 1041s Get a connection from the pool and perform an HTTP request. This is the 1041s lowest level call for making a request, so you'll need to specify all 1041s the raw details. 1041s 1041s .. note:: 1041s 1041s More commonly, it's appropriate to use a convenience method 1041s such as :meth:`request`. 1041s 1041s .. note:: 1041s 1041s `release_conn` will only behave as expected if 1041s `preload_content=False` because we want to make 1041s `preload_content=False` the default behaviour someday soon without 1041s breaking backwards compatibility. 1041s 1041s :param method: 1041s HTTP request method (such as GET, POST, PUT, etc.) 1041s 1041s :param url: 1041s The URL to perform the request on. 1041s 1041s :param body: 1041s Data to send in the request body, either :class:`str`, :class:`bytes`, 1041s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1041s 1041s :param headers: 1041s Dictionary of custom headers to send, such as User-Agent, 1041s If-None-Match, etc. If None, pool headers are used. If provided, 1041s these headers completely replace any pool-specific headers. 1041s 1041s :param retries: 1041s Configure the number of retries to allow before raising a 1041s :class:`~urllib3.exceptions.MaxRetryError` exception. 1041s 1041s Pass ``None`` to retry until you receive a response. Pass a 1041s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1041s over different types of retries. 1041s Pass an integer number to retry connection errors that many times, 1041s but no other types of errors. Pass zero to never retry. 1041s 1041s If ``False``, then retries are disabled and any exception is raised 1041s immediately. Also, instead of raising a MaxRetryError on redirects, 1041s the redirect response will be returned. 1041s 1041s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1041s 1041s :param redirect: 1041s If True, automatically handle redirects (status codes 301, 302, 1041s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1041s will disable redirect, too. 1041s 1041s :param assert_same_host: 1041s If ``True``, will make sure that the host of the pool requests is 1041s consistent else will raise HostChangedError. When ``False``, you can 1041s use the pool on an HTTP proxy and request foreign hosts. 1041s 1041s :param timeout: 1041s If specified, overrides the default timeout for this one 1041s request. It may be a float (in seconds) or an instance of 1041s :class:`urllib3.util.Timeout`. 1041s 1041s :param pool_timeout: 1041s If set and the pool is set to block=True, then this method will 1041s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1041s connection is available within the time period. 1041s 1041s :param bool preload_content: 1041s If True, the response's body will be preloaded into memory. 1041s 1041s :param bool decode_content: 1041s If True, will attempt to decode the body based on the 1041s 'content-encoding' header. 1041s 1041s :param release_conn: 1041s If False, then the urlopen call will not release the connection 1041s back into the pool once a response is received (but will release if 1041s you read the entire contents of the response such as when 1041s `preload_content=True`). This is useful if you're not preloading 1041s the response's content immediately. You will need to call 1041s ``r.release_conn()`` on the response ``r`` to return the connection 1041s back into the pool. If None, it takes the value of ``preload_content`` 1041s which defaults to ``True``. 1041s 1041s :param bool chunked: 1041s If True, urllib3 will send the body using chunked transfer 1041s encoding. Otherwise, urllib3 will send the body using the standard 1041s content-length form. Defaults to False. 1041s 1041s :param int body_pos: 1041s Position to seek to in file-like body in the event of a retry or 1041s redirect. Typically this won't need to be set because urllib3 will 1041s auto-populate the value when needed. 1041s """ 1041s parsed_url = parse_url(url) 1041s destination_scheme = parsed_url.scheme 1041s 1041s if headers is None: 1041s headers = self.headers 1041s 1041s if not isinstance(retries, Retry): 1041s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1041s 1041s if release_conn is None: 1041s release_conn = preload_content 1041s 1041s # Check host 1041s if assert_same_host and not self.is_same_host(url): 1041s raise HostChangedError(self, url, retries) 1041s 1041s # Ensure that the URL we're connecting to is properly encoded 1041s if url.startswith("/"): 1041s url = to_str(_encode_target(url)) 1041s else: 1041s url = to_str(parsed_url.url) 1041s 1041s conn = None 1041s 1041s # Track whether `conn` needs to be released before 1041s # returning/raising/recursing. Update this variable if necessary, and 1041s # leave `release_conn` constant throughout the function. That way, if 1041s # the function recurses, the original value of `release_conn` will be 1041s # passed down into the recursive call, and its value will be respected. 1041s # 1041s # See issue #651 [1] for details. 1041s # 1041s # [1] 1041s release_this_conn = release_conn 1041s 1041s http_tunnel_required = connection_requires_http_tunnel( 1041s self.proxy, self.proxy_config, destination_scheme 1041s ) 1041s 1041s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1041s # have to copy the headers dict so we can safely change it without those 1041s # changes being reflected in anyone else's copy. 1041s if not http_tunnel_required: 1041s headers = headers.copy() # type: ignore[attr-defined] 1041s headers.update(self.proxy_headers) # type: ignore[union-attr] 1041s 1041s # Must keep the exception bound to a separate variable or else Python 3 1041s # complains about UnboundLocalError. 1041s err = None 1041s 1041s # Keep track of whether we cleanly exited the except block. This 1041s # ensures we do proper cleanup in finally. 1041s clean_exit = False 1041s 1041s # Rewind body position, if needed. Record current position 1041s # for future rewinds in the event of a redirect/retry. 1041s body_pos = set_file_position(body, body_pos) 1041s 1041s try: 1041s # Request a connection from the queue. 1041s timeout_obj = self._get_timeout(timeout) 1041s conn = self._get_conn(timeout=pool_timeout) 1041s 1041s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1041s 1041s # Is this a closed/new connection that requires CONNECT tunnelling? 1041s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1041s try: 1041s self._prepare_proxy(conn) 1041s except (BaseSSLError, OSError, SocketTimeout) as e: 1041s self._raise_timeout( 1041s err=e, url=self.proxy.url, timeout_value=conn.timeout 1041s ) 1041s raise 1041s 1041s # If we're going to release the connection in ``finally:``, then 1041s # the response doesn't need to know about the connection. Otherwise 1041s # it will also try to release it and we'll have a double-release 1041s # mess. 1041s response_conn = conn if not release_conn else None 1041s 1041s # Make the request on the HTTPConnection object 1041s > response = self._make_request( 1041s conn, 1041s method, 1041s url, 1041s timeout=timeout_obj, 1041s body=body, 1041s headers=headers, 1041s chunked=chunked, 1041s retries=retries, 1041s response_conn=response_conn, 1041s preload_content=preload_content, 1041s decode_content=decode_content, 1041s **response_kw, 1041s ) 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1041s raise new_e 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1041s self._validate_conn(conn) 1041s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1041s conn.connect() 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1041s self.sock = sock = self._new_conn() 1041s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1041s 1041s self = 1041s 1041s def _new_conn(self) -> socket.socket: 1041s """Establish a socket connection and set nodelay settings on it. 1041s 1041s :return: New socket connection. 1041s """ 1041s try: 1041s sock = connection.create_connection( 1041s (self._dns_host, self.port), 1041s self.timeout, 1041s source_address=self.source_address, 1041s socket_options=self.socket_options, 1041s ) 1041s except socket.gaierror as e: 1041s raise NameResolutionError(self.host, self, e) from e 1041s except SocketTimeout as e: 1041s raise ConnectTimeoutError( 1041s self, 1041s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1041s ) from e 1041s 1041s except OSError as e: 1041s > raise NewConnectionError( 1041s self, f"Failed to establish a new connection: {e}" 1041s ) from e 1041s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1041s 1041s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1041s 1041s The above exception was the direct cause of the following exception: 1041s 1041s self = 1041s request = , stream = False 1041s timeout = Timeout(connect=None, read=None, total=None), verify = True 1041s cert = None, proxies = OrderedDict() 1041s 1041s def send( 1041s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1041s ): 1041s """Sends PreparedRequest object. Returns Response object. 1041s 1041s :param request: The :class:`PreparedRequest ` being sent. 1041s :param stream: (optional) Whether to stream the request content. 1041s :param timeout: (optional) How long to wait for the server to send 1041s data before giving up, as a float, or a :ref:`(connect timeout, 1041s read timeout) ` tuple. 1041s :type timeout: float or tuple or urllib3 Timeout object 1041s :param verify: (optional) Either a boolean, in which case it controls whether 1041s we verify the server's TLS certificate, or a string, in which case it 1041s must be a path to a CA bundle to use 1041s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1041s :param proxies: (optional) The proxies dictionary to apply to the request. 1041s :rtype: requests.Response 1041s """ 1041s 1041s try: 1041s conn = self.get_connection_with_tls_context( 1041s request, verify, proxies=proxies, cert=cert 1041s ) 1041s except LocationValueError as e: 1041s raise InvalidURL(e, request=request) 1041s 1041s self.cert_verify(conn, request.url, verify, cert) 1041s url = self.request_url(request, proxies) 1041s self.add_headers( 1041s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s > resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1042s retries = retries.increment( 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1042s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1042s _pool = 1042s _stacktrace = 1042s 1042s def increment( 1042s self, 1042s method: str | None = None, 1042s url: str | None = None, 1042s response: BaseHTTPResponse | None = None, 1042s error: Exception | None = None, 1042s _pool: ConnectionPool | None = None, 1042s _stacktrace: TracebackType | None = None, 1042s ) -> Retry: 1042s """Return a new Retry object with incremented retry counters. 1042s 1042s :param response: A response object, or None, if the server did not 1042s return a response. 1042s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1042s :param Exception error: An error encountered during the request, or 1042s None if the response was received successfully. 1042s 1042s :return: A new ``Retry`` object. 1042s """ 1042s if self.total is False and error: 1042s # Disabled, indicate to re-raise the error. 1042s raise reraise(type(error), error, _stacktrace) 1042s 1042s total = self.total 1042s if total is not None: 1042s total -= 1 1042s 1042s connect = self.connect 1042s read = self.read 1042s redirect = self.redirect 1042s status_count = self.status 1042s other = self.other 1042s cause = "unknown" 1042s status = None 1042s redirect_location = None 1042s 1042s if error and self._is_connection_error(error): 1042s # Connect retry? 1042s if connect is False: 1042s raise reraise(type(error), error, _stacktrace) 1042s elif connect is not None: 1042s connect -= 1 1042s 1042s elif error and self._is_read_error(error): 1042s # Read retry? 1042s if read is False or method is None or not self._is_method_retryable(method): 1042s raise reraise(type(error), error, _stacktrace) 1042s elif read is not None: 1042s read -= 1 1042s 1042s elif error: 1042s # Other retry? 1042s if other is not None: 1042s other -= 1 1042s 1042s elif response and response.get_redirect_location(): 1042s # Redirect retry? 1042s if redirect is not None: 1042s redirect -= 1 1042s cause = "too many redirects" 1042s response_redirect_location = response.get_redirect_location() 1042s if response_redirect_location: 1042s redirect_location = response_redirect_location 1042s status = response.status 1042s 1042s else: 1042s # Incrementing because of a server error like a 500 in 1042s # status_forcelist and the given method is in the allowed_methods 1042s cause = ResponseError.GENERIC_ERROR 1042s if response and response.status: 1042s if status_count is not None: 1042s status_count -= 1 1042s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1042s status = response.status 1042s 1042s history = self.history + ( 1042s RequestHistory(method, url, error, status, redirect_location), 1042s ) 1042s 1042s new_retry = self.new( 1042s total=total, 1042s connect=connect, 1042s read=read, 1042s redirect=redirect, 1042s status=status_count, 1042s other=other, 1042s history=history, 1042s ) 1042s 1042s if new_retry.is_exhausted(): 1042s reason = error or ResponseError(cause) 1042s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1042s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1042s 1042s During handling of the above exception, another exception occurred: 1042s 1042s def test_basic_offsets(): 1042s > enc = tiktoken.get_encoding("cl100k_base") 1042s 1042s tests/test_offsets.py:50: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1042s enc = Encoding(**constructor()) 1042s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1042s mergeable_ranks = load_tiktoken_bpe( 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1042s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1042s contents = read_file(blobpath) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1042s resp = requests.get(blobpath) 1042s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1042s return request("get", url, params=params, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1042s return session.request(method=method, url=url, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1042s resp = self.send(prep, **send_kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1042s r = adapter.send(request, **kwargs) 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s except (ProtocolError, OSError) as err: 1042s raise ConnectionError(err, request=request) 1042s 1042s except MaxRetryError as e: 1042s if isinstance(e.reason, ConnectTimeoutError): 1042s # TODO: Remove this in 3.0.0: see #2811 1042s if not isinstance(e.reason, NewConnectionError): 1042s raise ConnectTimeout(e, request=request) 1042s 1042s if isinstance(e.reason, ResponseError): 1042s raise RetryError(e, request=request) 1042s 1042s if isinstance(e.reason, _ProxyError): 1042s raise ProxyError(e, request=request) 1042s 1042s if isinstance(e.reason, _SSLError): 1042s # This branch is for urllib3 v1.22 and later. 1042s raise SSLError(e, request=request) 1042s 1042s > raise ConnectionError(e, request=request) 1042s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1042s _________________________________ test_pickle __________________________________ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s > sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1042s raise err 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1042s source_address = None, socket_options = [(6, 1, 1)] 1042s 1042s def create_connection( 1042s address: tuple[str, int], 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s source_address: tuple[str, int] | None = None, 1042s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1042s ) -> socket.socket: 1042s """Connect to *address* and return the socket object. 1042s 1042s Convenience function. Connect to *address* (a 2-tuple ``(host, 1042s port)``) and return the socket object. Passing the optional 1042s *timeout* parameter will set the timeout on the socket instance 1042s before attempting to connect. If no *timeout* is supplied, the 1042s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1042s is used. If *source_address* is set it must be a tuple of (host, port) 1042s for the socket to bind as a source address before making the connection. 1042s An host of '' or port 0 tells the OS to use the default. 1042s """ 1042s 1042s host, port = address 1042s if host.startswith("["): 1042s host = host.strip("[]") 1042s err = None 1042s 1042s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1042s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1042s # The original create_connection function always returns all records. 1042s family = allowed_gai_family() 1042s 1042s try: 1042s host.encode("idna") 1042s except UnicodeError: 1042s raise LocationParseError(f"'{host}', label empty or too long") from None 1042s 1042s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1042s af, socktype, proto, canonname, sa = res 1042s sock = None 1042s try: 1042s sock = socket.socket(af, socktype, proto) 1042s 1042s # If provided, set socket level options before connecting. 1042s _set_socket_options(sock, socket_options) 1042s 1042s if timeout is not _DEFAULT_TIMEOUT: 1042s sock.settimeout(timeout) 1042s if source_address: 1042s sock.bind(source_address) 1042s > sock.connect(sa) 1042s E ConnectionRefusedError: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1042s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1042s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s redirect = False, assert_same_host = False 1042s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1042s release_conn = False, chunked = False, body_pos = None, preload_content = False 1042s decode_content = False, response_kw = {} 1042s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1042s destination_scheme = None, conn = None, release_this_conn = True 1042s http_tunnel_required = False, err = None, clean_exit = False 1042s 1042s def urlopen( # type: ignore[override] 1042s self, 1042s method: str, 1042s url: str, 1042s body: _TYPE_BODY | None = None, 1042s headers: typing.Mapping[str, str] | None = None, 1042s retries: Retry | bool | int | None = None, 1042s redirect: bool = True, 1042s assert_same_host: bool = True, 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s pool_timeout: int | None = None, 1042s release_conn: bool | None = None, 1042s chunked: bool = False, 1042s body_pos: _TYPE_BODY_POSITION | None = None, 1042s preload_content: bool = True, 1042s decode_content: bool = True, 1042s **response_kw: typing.Any, 1042s ) -> BaseHTTPResponse: 1042s """ 1042s Get a connection from the pool and perform an HTTP request. This is the 1042s lowest level call for making a request, so you'll need to specify all 1042s the raw details. 1042s 1042s .. note:: 1042s 1042s More commonly, it's appropriate to use a convenience method 1042s such as :meth:`request`. 1042s 1042s .. note:: 1042s 1042s `release_conn` will only behave as expected if 1042s `preload_content=False` because we want to make 1042s `preload_content=False` the default behaviour someday soon without 1042s breaking backwards compatibility. 1042s 1042s :param method: 1042s HTTP request method (such as GET, POST, PUT, etc.) 1042s 1042s :param url: 1042s The URL to perform the request on. 1042s 1042s :param body: 1042s Data to send in the request body, either :class:`str`, :class:`bytes`, 1042s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1042s 1042s :param headers: 1042s Dictionary of custom headers to send, such as User-Agent, 1042s If-None-Match, etc. If None, pool headers are used. If provided, 1042s these headers completely replace any pool-specific headers. 1042s 1042s :param retries: 1042s Configure the number of retries to allow before raising a 1042s :class:`~urllib3.exceptions.MaxRetryError` exception. 1042s 1042s Pass ``None`` to retry until you receive a response. Pass a 1042s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1042s over different types of retries. 1042s Pass an integer number to retry connection errors that many times, 1042s but no other types of errors. Pass zero to never retry. 1042s 1042s If ``False``, then retries are disabled and any exception is raised 1042s immediately. Also, instead of raising a MaxRetryError on redirects, 1042s the redirect response will be returned. 1042s 1042s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1042s 1042s :param redirect: 1042s If True, automatically handle redirects (status codes 301, 302, 1042s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1042s will disable redirect, too. 1042s 1042s :param assert_same_host: 1042s If ``True``, will make sure that the host of the pool requests is 1042s consistent else will raise HostChangedError. When ``False``, you can 1042s use the pool on an HTTP proxy and request foreign hosts. 1042s 1042s :param timeout: 1042s If specified, overrides the default timeout for this one 1042s request. It may be a float (in seconds) or an instance of 1042s :class:`urllib3.util.Timeout`. 1042s 1042s :param pool_timeout: 1042s If set and the pool is set to block=True, then this method will 1042s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1042s connection is available within the time period. 1042s 1042s :param bool preload_content: 1042s If True, the response's body will be preloaded into memory. 1042s 1042s :param bool decode_content: 1042s If True, will attempt to decode the body based on the 1042s 'content-encoding' header. 1042s 1042s :param release_conn: 1042s If False, then the urlopen call will not release the connection 1042s back into the pool once a response is received (but will release if 1042s you read the entire contents of the response such as when 1042s `preload_content=True`). This is useful if you're not preloading 1042s the response's content immediately. You will need to call 1042s ``r.release_conn()`` on the response ``r`` to return the connection 1042s back into the pool. If None, it takes the value of ``preload_content`` 1042s which defaults to ``True``. 1042s 1042s :param bool chunked: 1042s If True, urllib3 will send the body using chunked transfer 1042s encoding. Otherwise, urllib3 will send the body using the standard 1042s content-length form. Defaults to False. 1042s 1042s :param int body_pos: 1042s Position to seek to in file-like body in the event of a retry or 1042s redirect. Typically this won't need to be set because urllib3 will 1042s auto-populate the value when needed. 1042s """ 1042s parsed_url = parse_url(url) 1042s destination_scheme = parsed_url.scheme 1042s 1042s if headers is None: 1042s headers = self.headers 1042s 1042s if not isinstance(retries, Retry): 1042s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1042s 1042s if release_conn is None: 1042s release_conn = preload_content 1042s 1042s # Check host 1042s if assert_same_host and not self.is_same_host(url): 1042s raise HostChangedError(self, url, retries) 1042s 1042s # Ensure that the URL we're connecting to is properly encoded 1042s if url.startswith("/"): 1042s url = to_str(_encode_target(url)) 1042s else: 1042s url = to_str(parsed_url.url) 1042s 1042s conn = None 1042s 1042s # Track whether `conn` needs to be released before 1042s # returning/raising/recursing. Update this variable if necessary, and 1042s # leave `release_conn` constant throughout the function. That way, if 1042s # the function recurses, the original value of `release_conn` will be 1042s # passed down into the recursive call, and its value will be respected. 1042s # 1042s # See issue #651 [1] for details. 1042s # 1042s # [1] 1042s release_this_conn = release_conn 1042s 1042s http_tunnel_required = connection_requires_http_tunnel( 1042s self.proxy, self.proxy_config, destination_scheme 1042s ) 1042s 1042s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1042s # have to copy the headers dict so we can safely change it without those 1042s # changes being reflected in anyone else's copy. 1042s if not http_tunnel_required: 1042s headers = headers.copy() # type: ignore[attr-defined] 1042s headers.update(self.proxy_headers) # type: ignore[union-attr] 1042s 1042s # Must keep the exception bound to a separate variable or else Python 3 1042s # complains about UnboundLocalError. 1042s err = None 1042s 1042s # Keep track of whether we cleanly exited the except block. This 1042s # ensures we do proper cleanup in finally. 1042s clean_exit = False 1042s 1042s # Rewind body position, if needed. Record current position 1042s # for future rewinds in the event of a redirect/retry. 1042s body_pos = set_file_position(body, body_pos) 1042s 1042s try: 1042s # Request a connection from the queue. 1042s timeout_obj = self._get_timeout(timeout) 1042s conn = self._get_conn(timeout=pool_timeout) 1042s 1042s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1042s 1042s # Is this a closed/new connection that requires CONNECT tunnelling? 1042s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1042s try: 1042s self._prepare_proxy(conn) 1042s except (BaseSSLError, OSError, SocketTimeout) as e: 1042s self._raise_timeout( 1042s err=e, url=self.proxy.url, timeout_value=conn.timeout 1042s ) 1042s raise 1042s 1042s # If we're going to release the connection in ``finally:``, then 1042s # the response doesn't need to know about the connection. Otherwise 1042s # it will also try to release it and we'll have a double-release 1042s # mess. 1042s response_conn = conn if not release_conn else None 1042s 1042s # Make the request on the HTTPConnection object 1042s > response = self._make_request( 1042s conn, 1042s method, 1042s url, 1042s timeout=timeout_obj, 1042s body=body, 1042s headers=headers, 1042s chunked=chunked, 1042s retries=retries, 1042s response_conn=response_conn, 1042s preload_content=preload_content, 1042s decode_content=decode_content, 1042s **response_kw, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1042s raise new_e 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1042s self._validate_conn(conn) 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1042s conn.connect() 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1042s self.sock = sock = self._new_conn() 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s except socket.gaierror as e: 1042s raise NameResolutionError(self.host, self, e) from e 1042s except SocketTimeout as e: 1042s raise ConnectTimeoutError( 1042s self, 1042s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1042s ) from e 1042s 1042s except OSError as e: 1042s > raise NewConnectionError( 1042s self, f"Failed to establish a new connection: {e}" 1042s ) from e 1042s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s > resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1042s retries = retries.increment( 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1042s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1042s _pool = 1042s _stacktrace = 1042s 1042s def increment( 1042s self, 1042s method: str | None = None, 1042s url: str | None = None, 1042s response: BaseHTTPResponse | None = None, 1042s error: Exception | None = None, 1042s _pool: ConnectionPool | None = None, 1042s _stacktrace: TracebackType | None = None, 1042s ) -> Retry: 1042s """Return a new Retry object with incremented retry counters. 1042s 1042s :param response: A response object, or None, if the server did not 1042s return a response. 1042s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1042s :param Exception error: An error encountered during the request, or 1042s None if the response was received successfully. 1042s 1042s :return: A new ``Retry`` object. 1042s """ 1042s if self.total is False and error: 1042s # Disabled, indicate to re-raise the error. 1042s raise reraise(type(error), error, _stacktrace) 1042s 1042s total = self.total 1042s if total is not None: 1042s total -= 1 1042s 1042s connect = self.connect 1042s read = self.read 1042s redirect = self.redirect 1042s status_count = self.status 1042s other = self.other 1042s cause = "unknown" 1042s status = None 1042s redirect_location = None 1042s 1042s if error and self._is_connection_error(error): 1042s # Connect retry? 1042s if connect is False: 1042s raise reraise(type(error), error, _stacktrace) 1042s elif connect is not None: 1042s connect -= 1 1042s 1042s elif error and self._is_read_error(error): 1042s # Read retry? 1042s if read is False or method is None or not self._is_method_retryable(method): 1042s raise reraise(type(error), error, _stacktrace) 1042s elif read is not None: 1042s read -= 1 1042s 1042s elif error: 1042s # Other retry? 1042s if other is not None: 1042s other -= 1 1042s 1042s elif response and response.get_redirect_location(): 1042s # Redirect retry? 1042s if redirect is not None: 1042s redirect -= 1 1042s cause = "too many redirects" 1042s response_redirect_location = response.get_redirect_location() 1042s if response_redirect_location: 1042s redirect_location = response_redirect_location 1042s status = response.status 1042s 1042s else: 1042s # Incrementing because of a server error like a 500 in 1042s # status_forcelist and the given method is in the allowed_methods 1042s cause = ResponseError.GENERIC_ERROR 1042s if response and response.status: 1042s if status_count is not None: 1042s status_count -= 1 1042s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1042s status = response.status 1042s 1042s history = self.history + ( 1042s RequestHistory(method, url, error, status, redirect_location), 1042s ) 1042s 1042s new_retry = self.new( 1042s total=total, 1042s connect=connect, 1042s read=read, 1042s redirect=redirect, 1042s status=status_count, 1042s other=other, 1042s history=history, 1042s ) 1042s 1042s if new_retry.is_exhausted(): 1042s reason = error or ResponseError(cause) 1042s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1042s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1042s 1042s During handling of the above exception, another exception occurred: 1042s 1042s def test_pickle(): 1042s import pickle 1042s 1042s > enc_old = tiktoken.get_encoding("r50k_base") 1042s 1042s tests/test_pickle.py:7: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1042s enc = Encoding(**constructor()) 1042s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1042s mergeable_ranks = load_tiktoken_bpe( 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1042s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1042s contents = read_file(blobpath) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1042s resp = requests.get(blobpath) 1042s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1042s return request("get", url, params=params, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1042s return session.request(method=method, url=url, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1042s resp = self.send(prep, **send_kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1042s r = adapter.send(request, **kwargs) 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s except (ProtocolError, OSError) as err: 1042s raise ConnectionError(err, request=request) 1042s 1042s except MaxRetryError as e: 1042s if isinstance(e.reason, ConnectTimeoutError): 1042s # TODO: Remove this in 3.0.0: see #2811 1042s if not isinstance(e.reason, NewConnectionError): 1042s raise ConnectTimeout(e, request=request) 1042s 1042s if isinstance(e.reason, ResponseError): 1042s raise RetryError(e, request=request) 1042s 1042s if isinstance(e.reason, _ProxyError): 1042s raise ProxyError(e, request=request) 1042s 1042s if isinstance(e.reason, _SSLError): 1042s # This branch is for urllib3 v1.22 and later. 1042s raise SSLError(e, request=request) 1042s 1042s > raise ConnectionError(e, request=request) 1042s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1042s _________________________________ test_simple __________________________________ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s > sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1042s raise err 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1042s source_address = None, socket_options = [(6, 1, 1)] 1042s 1042s def create_connection( 1042s address: tuple[str, int], 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s source_address: tuple[str, int] | None = None, 1042s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1042s ) -> socket.socket: 1042s """Connect to *address* and return the socket object. 1042s 1042s Convenience function. Connect to *address* (a 2-tuple ``(host, 1042s port)``) and return the socket object. Passing the optional 1042s *timeout* parameter will set the timeout on the socket instance 1042s before attempting to connect. If no *timeout* is supplied, the 1042s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1042s is used. If *source_address* is set it must be a tuple of (host, port) 1042s for the socket to bind as a source address before making the connection. 1042s An host of '' or port 0 tells the OS to use the default. 1042s """ 1042s 1042s host, port = address 1042s if host.startswith("["): 1042s host = host.strip("[]") 1042s err = None 1042s 1042s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1042s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1042s # The original create_connection function always returns all records. 1042s family = allowed_gai_family() 1042s 1042s try: 1042s host.encode("idna") 1042s except UnicodeError: 1042s raise LocationParseError(f"'{host}', label empty or too long") from None 1042s 1042s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1042s af, socktype, proto, canonname, sa = res 1042s sock = None 1042s try: 1042s sock = socket.socket(af, socktype, proto) 1042s 1042s # If provided, set socket level options before connecting. 1042s _set_socket_options(sock, socket_options) 1042s 1042s if timeout is not _DEFAULT_TIMEOUT: 1042s sock.settimeout(timeout) 1042s if source_address: 1042s sock.bind(source_address) 1042s > sock.connect(sa) 1042s E ConnectionRefusedError: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1042s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1042s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s redirect = False, assert_same_host = False 1042s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1042s release_conn = False, chunked = False, body_pos = None, preload_content = False 1042s decode_content = False, response_kw = {} 1042s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1042s destination_scheme = None, conn = None, release_this_conn = True 1042s http_tunnel_required = False, err = None, clean_exit = False 1042s 1042s def urlopen( # type: ignore[override] 1042s self, 1042s method: str, 1042s url: str, 1042s body: _TYPE_BODY | None = None, 1042s headers: typing.Mapping[str, str] | None = None, 1042s retries: Retry | bool | int | None = None, 1042s redirect: bool = True, 1042s assert_same_host: bool = True, 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s pool_timeout: int | None = None, 1042s release_conn: bool | None = None, 1042s chunked: bool = False, 1042s body_pos: _TYPE_BODY_POSITION | None = None, 1042s preload_content: bool = True, 1042s decode_content: bool = True, 1042s **response_kw: typing.Any, 1042s ) -> BaseHTTPResponse: 1042s """ 1042s Get a connection from the pool and perform an HTTP request. This is the 1042s lowest level call for making a request, so you'll need to specify all 1042s the raw details. 1042s 1042s .. note:: 1042s 1042s More commonly, it's appropriate to use a convenience method 1042s such as :meth:`request`. 1042s 1042s .. note:: 1042s 1042s `release_conn` will only behave as expected if 1042s `preload_content=False` because we want to make 1042s `preload_content=False` the default behaviour someday soon without 1042s breaking backwards compatibility. 1042s 1042s :param method: 1042s HTTP request method (such as GET, POST, PUT, etc.) 1042s 1042s :param url: 1042s The URL to perform the request on. 1042s 1042s :param body: 1042s Data to send in the request body, either :class:`str`, :class:`bytes`, 1042s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1042s 1042s :param headers: 1042s Dictionary of custom headers to send, such as User-Agent, 1042s If-None-Match, etc. If None, pool headers are used. If provided, 1042s these headers completely replace any pool-specific headers. 1042s 1042s :param retries: 1042s Configure the number of retries to allow before raising a 1042s :class:`~urllib3.exceptions.MaxRetryError` exception. 1042s 1042s Pass ``None`` to retry until you receive a response. Pass a 1042s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1042s over different types of retries. 1042s Pass an integer number to retry connection errors that many times, 1042s but no other types of errors. Pass zero to never retry. 1042s 1042s If ``False``, then retries are disabled and any exception is raised 1042s immediately. Also, instead of raising a MaxRetryError on redirects, 1042s the redirect response will be returned. 1042s 1042s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1042s 1042s :param redirect: 1042s If True, automatically handle redirects (status codes 301, 302, 1042s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1042s will disable redirect, too. 1042s 1042s :param assert_same_host: 1042s If ``True``, will make sure that the host of the pool requests is 1042s consistent else will raise HostChangedError. When ``False``, you can 1042s use the pool on an HTTP proxy and request foreign hosts. 1042s 1042s :param timeout: 1042s If specified, overrides the default timeout for this one 1042s request. It may be a float (in seconds) or an instance of 1042s :class:`urllib3.util.Timeout`. 1042s 1042s :param pool_timeout: 1042s If set and the pool is set to block=True, then this method will 1042s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1042s connection is available within the time period. 1042s 1042s :param bool preload_content: 1042s If True, the response's body will be preloaded into memory. 1042s 1042s :param bool decode_content: 1042s If True, will attempt to decode the body based on the 1042s 'content-encoding' header. 1042s 1042s :param release_conn: 1042s If False, then the urlopen call will not release the connection 1042s back into the pool once a response is received (but will release if 1042s you read the entire contents of the response such as when 1042s `preload_content=True`). This is useful if you're not preloading 1042s the response's content immediately. You will need to call 1042s ``r.release_conn()`` on the response ``r`` to return the connection 1042s back into the pool. If None, it takes the value of ``preload_content`` 1042s which defaults to ``True``. 1042s 1042s :param bool chunked: 1042s If True, urllib3 will send the body using chunked transfer 1042s encoding. Otherwise, urllib3 will send the body using the standard 1042s content-length form. Defaults to False. 1042s 1042s :param int body_pos: 1042s Position to seek to in file-like body in the event of a retry or 1042s redirect. Typically this won't need to be set because urllib3 will 1042s auto-populate the value when needed. 1042s """ 1042s parsed_url = parse_url(url) 1042s destination_scheme = parsed_url.scheme 1042s 1042s if headers is None: 1042s headers = self.headers 1042s 1042s if not isinstance(retries, Retry): 1042s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1042s 1042s if release_conn is None: 1042s release_conn = preload_content 1042s 1042s # Check host 1042s if assert_same_host and not self.is_same_host(url): 1042s raise HostChangedError(self, url, retries) 1042s 1042s # Ensure that the URL we're connecting to is properly encoded 1042s if url.startswith("/"): 1042s url = to_str(_encode_target(url)) 1042s else: 1042s url = to_str(parsed_url.url) 1042s 1042s conn = None 1042s 1042s # Track whether `conn` needs to be released before 1042s # returning/raising/recursing. Update this variable if necessary, and 1042s # leave `release_conn` constant throughout the function. That way, if 1042s # the function recurses, the original value of `release_conn` will be 1042s # passed down into the recursive call, and its value will be respected. 1042s # 1042s # See issue #651 [1] for details. 1042s # 1042s # [1] 1042s release_this_conn = release_conn 1042s 1042s http_tunnel_required = connection_requires_http_tunnel( 1042s self.proxy, self.proxy_config, destination_scheme 1042s ) 1042s 1042s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1042s # have to copy the headers dict so we can safely change it without those 1042s # changes being reflected in anyone else's copy. 1042s if not http_tunnel_required: 1042s headers = headers.copy() # type: ignore[attr-defined] 1042s headers.update(self.proxy_headers) # type: ignore[union-attr] 1042s 1042s # Must keep the exception bound to a separate variable or else Python 3 1042s # complains about UnboundLocalError. 1042s err = None 1042s 1042s # Keep track of whether we cleanly exited the except block. This 1042s # ensures we do proper cleanup in finally. 1042s clean_exit = False 1042s 1042s # Rewind body position, if needed. Record current position 1042s # for future rewinds in the event of a redirect/retry. 1042s body_pos = set_file_position(body, body_pos) 1042s 1042s try: 1042s # Request a connection from the queue. 1042s timeout_obj = self._get_timeout(timeout) 1042s conn = self._get_conn(timeout=pool_timeout) 1042s 1042s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1042s 1042s # Is this a closed/new connection that requires CONNECT tunnelling? 1042s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1042s try: 1042s self._prepare_proxy(conn) 1042s except (BaseSSLError, OSError, SocketTimeout) as e: 1042s self._raise_timeout( 1042s err=e, url=self.proxy.url, timeout_value=conn.timeout 1042s ) 1042s raise 1042s 1042s # If we're going to release the connection in ``finally:``, then 1042s # the response doesn't need to know about the connection. Otherwise 1042s # it will also try to release it and we'll have a double-release 1042s # mess. 1042s response_conn = conn if not release_conn else None 1042s 1042s # Make the request on the HTTPConnection object 1042s > response = self._make_request( 1042s conn, 1042s method, 1042s url, 1042s timeout=timeout_obj, 1042s body=body, 1042s headers=headers, 1042s chunked=chunked, 1042s retries=retries, 1042s response_conn=response_conn, 1042s preload_content=preload_content, 1042s decode_content=decode_content, 1042s **response_kw, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1042s raise new_e 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1042s self._validate_conn(conn) 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1042s conn.connect() 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1042s self.sock = sock = self._new_conn() 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s except socket.gaierror as e: 1042s raise NameResolutionError(self.host, self, e) from e 1042s except SocketTimeout as e: 1042s raise ConnectTimeoutError( 1042s self, 1042s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1042s ) from e 1042s 1042s except OSError as e: 1042s > raise NewConnectionError( 1042s self, f"Failed to establish a new connection: {e}" 1042s ) from e 1042s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s > resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1042s retries = retries.increment( 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1042s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1042s _pool = 1042s _stacktrace = 1042s 1042s def increment( 1042s self, 1042s method: str | None = None, 1042s url: str | None = None, 1042s response: BaseHTTPResponse | None = None, 1042s error: Exception | None = None, 1042s _pool: ConnectionPool | None = None, 1042s _stacktrace: TracebackType | None = None, 1042s ) -> Retry: 1042s """Return a new Retry object with incremented retry counters. 1042s 1042s :param response: A response object, or None, if the server did not 1042s return a response. 1042s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1042s :param Exception error: An error encountered during the request, or 1042s None if the response was received successfully. 1042s 1042s :return: A new ``Retry`` object. 1042s """ 1042s if self.total is False and error: 1042s # Disabled, indicate to re-raise the error. 1042s raise reraise(type(error), error, _stacktrace) 1042s 1042s total = self.total 1042s if total is not None: 1042s total -= 1 1042s 1042s connect = self.connect 1042s read = self.read 1042s redirect = self.redirect 1042s status_count = self.status 1042s other = self.other 1042s cause = "unknown" 1042s status = None 1042s redirect_location = None 1042s 1042s if error and self._is_connection_error(error): 1042s # Connect retry? 1042s if connect is False: 1042s raise reraise(type(error), error, _stacktrace) 1042s elif connect is not None: 1042s connect -= 1 1042s 1042s elif error and self._is_read_error(error): 1042s # Read retry? 1042s if read is False or method is None or not self._is_method_retryable(method): 1042s raise reraise(type(error), error, _stacktrace) 1042s elif read is not None: 1042s read -= 1 1042s 1042s elif error: 1042s # Other retry? 1042s if other is not None: 1042s other -= 1 1042s 1042s elif response and response.get_redirect_location(): 1042s # Redirect retry? 1042s if redirect is not None: 1042s redirect -= 1 1042s cause = "too many redirects" 1042s response_redirect_location = response.get_redirect_location() 1042s if response_redirect_location: 1042s redirect_location = response_redirect_location 1042s status = response.status 1042s 1042s else: 1042s # Incrementing because of a server error like a 500 in 1042s # status_forcelist and the given method is in the allowed_methods 1042s cause = ResponseError.GENERIC_ERROR 1042s if response and response.status: 1042s if status_count is not None: 1042s status_count -= 1 1042s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1042s status = response.status 1042s 1042s history = self.history + ( 1042s RequestHistory(method, url, error, status, redirect_location), 1042s ) 1042s 1042s new_retry = self.new( 1042s total=total, 1042s connect=connect, 1042s read=read, 1042s redirect=redirect, 1042s status=status_count, 1042s other=other, 1042s history=history, 1042s ) 1042s 1042s if new_retry.is_exhausted(): 1042s reason = error or ResponseError(cause) 1042s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1042s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1042s 1042s During handling of the above exception, another exception occurred: 1042s 1042s def test_simple(): 1042s # Note that there are more actual tests, they're just not currently public :-) 1042s > enc = tiktoken.get_encoding("gpt2") 1042s 1042s tests/test_simple_public.py:9: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1042s enc = Encoding(**constructor()) 1042s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1042s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1042s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1042s contents = read_file(blobpath) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1042s resp = requests.get(blobpath) 1042s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1042s return request("get", url, params=params, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1042s return session.request(method=method, url=url, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1042s resp = self.send(prep, **send_kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1042s r = adapter.send(request, **kwargs) 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s except (ProtocolError, OSError) as err: 1042s raise ConnectionError(err, request=request) 1042s 1042s except MaxRetryError as e: 1042s if isinstance(e.reason, ConnectTimeoutError): 1042s # TODO: Remove this in 3.0.0: see #2811 1042s if not isinstance(e.reason, NewConnectionError): 1042s raise ConnectTimeout(e, request=request) 1042s 1042s if isinstance(e.reason, ResponseError): 1042s raise RetryError(e, request=request) 1042s 1042s if isinstance(e.reason, _ProxyError): 1042s raise ProxyError(e, request=request) 1042s 1042s if isinstance(e.reason, _SSLError): 1042s # This branch is for urllib3 v1.22 and later. 1042s raise SSLError(e, request=request) 1042s 1042s > raise ConnectionError(e, request=request) 1042s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1042s ___________________________ test_encoding_for_model ____________________________ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s > sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1042s raise err 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1042s source_address = None, socket_options = [(6, 1, 1)] 1042s 1042s def create_connection( 1042s address: tuple[str, int], 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s source_address: tuple[str, int] | None = None, 1042s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1042s ) -> socket.socket: 1042s """Connect to *address* and return the socket object. 1042s 1042s Convenience function. Connect to *address* (a 2-tuple ``(host, 1042s port)``) and return the socket object. Passing the optional 1042s *timeout* parameter will set the timeout on the socket instance 1042s before attempting to connect. If no *timeout* is supplied, the 1042s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1042s is used. If *source_address* is set it must be a tuple of (host, port) 1042s for the socket to bind as a source address before making the connection. 1042s An host of '' or port 0 tells the OS to use the default. 1042s """ 1042s 1042s host, port = address 1042s if host.startswith("["): 1042s host = host.strip("[]") 1042s err = None 1042s 1042s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1042s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1042s # The original create_connection function always returns all records. 1042s family = allowed_gai_family() 1042s 1042s try: 1042s host.encode("idna") 1042s except UnicodeError: 1042s raise LocationParseError(f"'{host}', label empty or too long") from None 1042s 1042s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1042s af, socktype, proto, canonname, sa = res 1042s sock = None 1042s try: 1042s sock = socket.socket(af, socktype, proto) 1042s 1042s # If provided, set socket level options before connecting. 1042s _set_socket_options(sock, socket_options) 1042s 1042s if timeout is not _DEFAULT_TIMEOUT: 1042s sock.settimeout(timeout) 1042s if source_address: 1042s sock.bind(source_address) 1042s > sock.connect(sa) 1042s E ConnectionRefusedError: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1042s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1042s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s redirect = False, assert_same_host = False 1042s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1042s release_conn = False, chunked = False, body_pos = None, preload_content = False 1042s decode_content = False, response_kw = {} 1042s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1042s destination_scheme = None, conn = None, release_this_conn = True 1042s http_tunnel_required = False, err = None, clean_exit = False 1042s 1042s def urlopen( # type: ignore[override] 1042s self, 1042s method: str, 1042s url: str, 1042s body: _TYPE_BODY | None = None, 1042s headers: typing.Mapping[str, str] | None = None, 1042s retries: Retry | bool | int | None = None, 1042s redirect: bool = True, 1042s assert_same_host: bool = True, 1042s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1042s pool_timeout: int | None = None, 1042s release_conn: bool | None = None, 1042s chunked: bool = False, 1042s body_pos: _TYPE_BODY_POSITION | None = None, 1042s preload_content: bool = True, 1042s decode_content: bool = True, 1042s **response_kw: typing.Any, 1042s ) -> BaseHTTPResponse: 1042s """ 1042s Get a connection from the pool and perform an HTTP request. This is the 1042s lowest level call for making a request, so you'll need to specify all 1042s the raw details. 1042s 1042s .. note:: 1042s 1042s More commonly, it's appropriate to use a convenience method 1042s such as :meth:`request`. 1042s 1042s .. note:: 1042s 1042s `release_conn` will only behave as expected if 1042s `preload_content=False` because we want to make 1042s `preload_content=False` the default behaviour someday soon without 1042s breaking backwards compatibility. 1042s 1042s :param method: 1042s HTTP request method (such as GET, POST, PUT, etc.) 1042s 1042s :param url: 1042s The URL to perform the request on. 1042s 1042s :param body: 1042s Data to send in the request body, either :class:`str`, :class:`bytes`, 1042s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1042s 1042s :param headers: 1042s Dictionary of custom headers to send, such as User-Agent, 1042s If-None-Match, etc. If None, pool headers are used. If provided, 1042s these headers completely replace any pool-specific headers. 1042s 1042s :param retries: 1042s Configure the number of retries to allow before raising a 1042s :class:`~urllib3.exceptions.MaxRetryError` exception. 1042s 1042s Pass ``None`` to retry until you receive a response. Pass a 1042s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1042s over different types of retries. 1042s Pass an integer number to retry connection errors that many times, 1042s but no other types of errors. Pass zero to never retry. 1042s 1042s If ``False``, then retries are disabled and any exception is raised 1042s immediately. Also, instead of raising a MaxRetryError on redirects, 1042s the redirect response will be returned. 1042s 1042s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1042s 1042s :param redirect: 1042s If True, automatically handle redirects (status codes 301, 302, 1042s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1042s will disable redirect, too. 1042s 1042s :param assert_same_host: 1042s If ``True``, will make sure that the host of the pool requests is 1042s consistent else will raise HostChangedError. When ``False``, you can 1042s use the pool on an HTTP proxy and request foreign hosts. 1042s 1042s :param timeout: 1042s If specified, overrides the default timeout for this one 1042s request. It may be a float (in seconds) or an instance of 1042s :class:`urllib3.util.Timeout`. 1042s 1042s :param pool_timeout: 1042s If set and the pool is set to block=True, then this method will 1042s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1042s connection is available within the time period. 1042s 1042s :param bool preload_content: 1042s If True, the response's body will be preloaded into memory. 1042s 1042s :param bool decode_content: 1042s If True, will attempt to decode the body based on the 1042s 'content-encoding' header. 1042s 1042s :param release_conn: 1042s If False, then the urlopen call will not release the connection 1042s back into the pool once a response is received (but will release if 1042s you read the entire contents of the response such as when 1042s `preload_content=True`). This is useful if you're not preloading 1042s the response's content immediately. You will need to call 1042s ``r.release_conn()`` on the response ``r`` to return the connection 1042s back into the pool. If None, it takes the value of ``preload_content`` 1042s which defaults to ``True``. 1042s 1042s :param bool chunked: 1042s If True, urllib3 will send the body using chunked transfer 1042s encoding. Otherwise, urllib3 will send the body using the standard 1042s content-length form. Defaults to False. 1042s 1042s :param int body_pos: 1042s Position to seek to in file-like body in the event of a retry or 1042s redirect. Typically this won't need to be set because urllib3 will 1042s auto-populate the value when needed. 1042s """ 1042s parsed_url = parse_url(url) 1042s destination_scheme = parsed_url.scheme 1042s 1042s if headers is None: 1042s headers = self.headers 1042s 1042s if not isinstance(retries, Retry): 1042s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1042s 1042s if release_conn is None: 1042s release_conn = preload_content 1042s 1042s # Check host 1042s if assert_same_host and not self.is_same_host(url): 1042s raise HostChangedError(self, url, retries) 1042s 1042s # Ensure that the URL we're connecting to is properly encoded 1042s if url.startswith("/"): 1042s url = to_str(_encode_target(url)) 1042s else: 1042s url = to_str(parsed_url.url) 1042s 1042s conn = None 1042s 1042s # Track whether `conn` needs to be released before 1042s # returning/raising/recursing. Update this variable if necessary, and 1042s # leave `release_conn` constant throughout the function. That way, if 1042s # the function recurses, the original value of `release_conn` will be 1042s # passed down into the recursive call, and its value will be respected. 1042s # 1042s # See issue #651 [1] for details. 1042s # 1042s # [1] 1042s release_this_conn = release_conn 1042s 1042s http_tunnel_required = connection_requires_http_tunnel( 1042s self.proxy, self.proxy_config, destination_scheme 1042s ) 1042s 1042s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1042s # have to copy the headers dict so we can safely change it without those 1042s # changes being reflected in anyone else's copy. 1042s if not http_tunnel_required: 1042s headers = headers.copy() # type: ignore[attr-defined] 1042s headers.update(self.proxy_headers) # type: ignore[union-attr] 1042s 1042s # Must keep the exception bound to a separate variable or else Python 3 1042s # complains about UnboundLocalError. 1042s err = None 1042s 1042s # Keep track of whether we cleanly exited the except block. This 1042s # ensures we do proper cleanup in finally. 1042s clean_exit = False 1042s 1042s # Rewind body position, if needed. Record current position 1042s # for future rewinds in the event of a redirect/retry. 1042s body_pos = set_file_position(body, body_pos) 1042s 1042s try: 1042s # Request a connection from the queue. 1042s timeout_obj = self._get_timeout(timeout) 1042s conn = self._get_conn(timeout=pool_timeout) 1042s 1042s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1042s 1042s # Is this a closed/new connection that requires CONNECT tunnelling? 1042s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1042s try: 1042s self._prepare_proxy(conn) 1042s except (BaseSSLError, OSError, SocketTimeout) as e: 1042s self._raise_timeout( 1042s err=e, url=self.proxy.url, timeout_value=conn.timeout 1042s ) 1042s raise 1042s 1042s # If we're going to release the connection in ``finally:``, then 1042s # the response doesn't need to know about the connection. Otherwise 1042s # it will also try to release it and we'll have a double-release 1042s # mess. 1042s response_conn = conn if not release_conn else None 1042s 1042s # Make the request on the HTTPConnection object 1042s > response = self._make_request( 1042s conn, 1042s method, 1042s url, 1042s timeout=timeout_obj, 1042s body=body, 1042s headers=headers, 1042s chunked=chunked, 1042s retries=retries, 1042s response_conn=response_conn, 1042s preload_content=preload_content, 1042s decode_content=decode_content, 1042s **response_kw, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1042s raise new_e 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1042s self._validate_conn(conn) 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1042s conn.connect() 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1042s self.sock = sock = self._new_conn() 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s 1042s def _new_conn(self) -> socket.socket: 1042s """Establish a socket connection and set nodelay settings on it. 1042s 1042s :return: New socket connection. 1042s """ 1042s try: 1042s sock = connection.create_connection( 1042s (self._dns_host, self.port), 1042s self.timeout, 1042s source_address=self.source_address, 1042s socket_options=self.socket_options, 1042s ) 1042s except socket.gaierror as e: 1042s raise NameResolutionError(self.host, self, e) from e 1042s except SocketTimeout as e: 1042s raise ConnectTimeoutError( 1042s self, 1042s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1042s ) from e 1042s 1042s except OSError as e: 1042s > raise NewConnectionError( 1042s self, f"Failed to establish a new connection: {e}" 1042s ) from e 1042s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1042s 1042s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1042s 1042s The above exception was the direct cause of the following exception: 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s > resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1042s retries = retries.increment( 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1042s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1042s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1042s _pool = 1042s _stacktrace = 1042s 1042s def increment( 1042s self, 1042s method: str | None = None, 1042s url: str | None = None, 1042s response: BaseHTTPResponse | None = None, 1042s error: Exception | None = None, 1042s _pool: ConnectionPool | None = None, 1042s _stacktrace: TracebackType | None = None, 1042s ) -> Retry: 1042s """Return a new Retry object with incremented retry counters. 1042s 1042s :param response: A response object, or None, if the server did not 1042s return a response. 1042s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1042s :param Exception error: An error encountered during the request, or 1042s None if the response was received successfully. 1042s 1042s :return: A new ``Retry`` object. 1042s """ 1042s if self.total is False and error: 1042s # Disabled, indicate to re-raise the error. 1042s raise reraise(type(error), error, _stacktrace) 1042s 1042s total = self.total 1042s if total is not None: 1042s total -= 1 1042s 1042s connect = self.connect 1042s read = self.read 1042s redirect = self.redirect 1042s status_count = self.status 1042s other = self.other 1042s cause = "unknown" 1042s status = None 1042s redirect_location = None 1042s 1042s if error and self._is_connection_error(error): 1042s # Connect retry? 1042s if connect is False: 1042s raise reraise(type(error), error, _stacktrace) 1042s elif connect is not None: 1042s connect -= 1 1042s 1042s elif error and self._is_read_error(error): 1042s # Read retry? 1042s if read is False or method is None or not self._is_method_retryable(method): 1042s raise reraise(type(error), error, _stacktrace) 1042s elif read is not None: 1042s read -= 1 1042s 1042s elif error: 1042s # Other retry? 1042s if other is not None: 1042s other -= 1 1042s 1042s elif response and response.get_redirect_location(): 1042s # Redirect retry? 1042s if redirect is not None: 1042s redirect -= 1 1042s cause = "too many redirects" 1042s response_redirect_location = response.get_redirect_location() 1042s if response_redirect_location: 1042s redirect_location = response_redirect_location 1042s status = response.status 1042s 1042s else: 1042s # Incrementing because of a server error like a 500 in 1042s # status_forcelist and the given method is in the allowed_methods 1042s cause = ResponseError.GENERIC_ERROR 1042s if response and response.status: 1042s if status_count is not None: 1042s status_count -= 1 1042s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1042s status = response.status 1042s 1042s history = self.history + ( 1042s RequestHistory(method, url, error, status, redirect_location), 1042s ) 1042s 1042s new_retry = self.new( 1042s total=total, 1042s connect=connect, 1042s read=read, 1042s redirect=redirect, 1042s status=status_count, 1042s other=other, 1042s history=history, 1042s ) 1042s 1042s if new_retry.is_exhausted(): 1042s reason = error or ResponseError(cause) 1042s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1042s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1042s 1042s During handling of the above exception, another exception occurred: 1042s 1042s def test_encoding_for_model(): 1042s > enc = tiktoken.encoding_for_model("gpt2") 1042s 1042s tests/test_simple_public.py:26: 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 1042s return get_encoding(encoding_name_for_model(model_name)) 1042s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1042s enc = Encoding(**constructor()) 1042s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1042s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1042s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1042s contents = read_file(blobpath) 1042s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1042s resp = requests.get(blobpath) 1042s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1042s return request("get", url, params=params, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1042s return session.request(method=method, url=url, **kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1042s resp = self.send(prep, **send_kwargs) 1042s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1042s r = adapter.send(request, **kwargs) 1042s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1042s 1042s self = 1042s request = , stream = False 1042s timeout = Timeout(connect=None, read=None, total=None), verify = True 1042s cert = None, proxies = OrderedDict() 1042s 1042s def send( 1042s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1042s ): 1042s """Sends PreparedRequest object. Returns Response object. 1042s 1042s :param request: The :class:`PreparedRequest ` being sent. 1042s :param stream: (optional) Whether to stream the request content. 1042s :param timeout: (optional) How long to wait for the server to send 1042s data before giving up, as a float, or a :ref:`(connect timeout, 1042s read timeout) ` tuple. 1042s :type timeout: float or tuple or urllib3 Timeout object 1042s :param verify: (optional) Either a boolean, in which case it controls whether 1042s we verify the server's TLS certificate, or a string, in which case it 1042s must be a path to a CA bundle to use 1042s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1042s :param proxies: (optional) The proxies dictionary to apply to the request. 1042s :rtype: requests.Response 1042s """ 1042s 1042s try: 1042s conn = self.get_connection_with_tls_context( 1042s request, verify, proxies=proxies, cert=cert 1042s ) 1042s except LocationValueError as e: 1042s raise InvalidURL(e, request=request) 1042s 1042s self.cert_verify(conn, request.url, verify, cert) 1042s url = self.request_url(request, proxies) 1042s self.add_headers( 1042s request, 1042s stream=stream, 1042s timeout=timeout, 1042s verify=verify, 1042s cert=cert, 1042s proxies=proxies, 1042s ) 1042s 1042s chunked = not (request.body is None or "Content-Length" in request.headers) 1042s 1042s if isinstance(timeout, tuple): 1042s try: 1042s connect, read = timeout 1042s timeout = TimeoutSauce(connect=connect, read=read) 1042s except ValueError: 1042s raise ValueError( 1042s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1042s f"or a single float to set both timeouts to the same value." 1042s ) 1042s elif isinstance(timeout, TimeoutSauce): 1042s pass 1042s else: 1042s timeout = TimeoutSauce(connect=timeout, read=timeout) 1042s 1042s try: 1042s resp = conn.urlopen( 1042s method=request.method, 1042s url=url, 1042s body=request.body, 1042s headers=request.headers, 1042s redirect=False, 1042s assert_same_host=False, 1042s preload_content=False, 1042s decode_content=False, 1042s retries=self.max_retries, 1042s timeout=timeout, 1042s chunked=chunked, 1042s ) 1042s 1042s except (ProtocolError, OSError) as err: 1042s raise ConnectionError(err, request=request) 1042s 1042s except MaxRetryError as e: 1042s if isinstance(e.reason, ConnectTimeoutError): 1042s # TODO: Remove this in 3.0.0: see #2811 1042s if not isinstance(e.reason, NewConnectionError): 1042s raise ConnectTimeout(e, request=request) 1042s 1042s if isinstance(e.reason, ResponseError): 1042s raise RetryError(e, request=request) 1042s 1042s if isinstance(e.reason, _ProxyError): 1042s raise ProxyError(e, request=request) 1042s 1042s if isinstance(e.reason, _SSLError): 1042s # This branch is for urllib3 v1.22 and later. 1042s raise SSLError(e, request=request) 1042s 1042s > raise ConnectionError(e, request=request) 1042s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1042s 1042s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1042s =========================== short test summary info ============================ 1042s FAILED tests/test_encoding.py::test_simple - requests.exceptions.ConnectionEr... 1042s FAILED tests/test_encoding.py::test_simple_repeated - requests.exceptions.Con... 1042s FAILED tests/test_encoding.py::test_simple_regex - requests.exceptions.Connec... 1042s FAILED tests/test_encoding.py::test_basic_encode - requests.exceptions.Connec... 1042s FAILED tests/test_encoding.py::test_encode_empty - requests.exceptions.Connec... 1042s FAILED tests/test_encoding.py::test_encode_bytes - requests.exceptions.Connec... 1042s FAILED tests/test_encoding.py::test_encode_surrogate_pairs - requests.excepti... 1042s FAILED tests/test_encoding.py::test_catastrophically_repetitive[r50k_base] - ... 1042s FAILED tests/test_encoding.py::test_catastrophically_repetitive[cl100k_base] 1042s FAILED tests/test_encoding.py::test_basic_roundtrip[r50k_base] - requests.exc... 1042s FAILED tests/test_encoding.py::test_basic_roundtrip[cl100k_base] - requests.e... 1042s FAILED tests/test_encoding.py::test_hyp_roundtrip[r50k_base] - requests.excep... 1042s FAILED tests/test_encoding.py::test_hyp_roundtrip[cl100k_base] - requests.exc... 1042s FAILED tests/test_encoding.py::test_single_token_roundtrip[r50k_base] - reque... 1042s FAILED tests/test_encoding.py::test_single_token_roundtrip[cl100k_base] - req... 1042s FAILED tests/test_encoding.py::test_special_token - requests.exceptions.Conne... 1042s FAILED tests/test_encoding.py::test_hyp_special_ordinary[r50k_base] - request... 1042s FAILED tests/test_encoding.py::test_hyp_special_ordinary[cl100k_base] - reque... 1042s FAILED tests/test_encoding.py::test_batch_encode[r50k_base] - requests.except... 1042s FAILED tests/test_encoding.py::test_batch_encode[cl100k_base] - requests.exce... 1042s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[r50k_base] - requests... 1042s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[cl100k_base] - reques... 1042s FAILED tests/test_misc.py::test_encoding_for_model - requests.exceptions.Conn... 1042s FAILED tests/test_offsets.py::test_hyp_offsets[cl100k_base] - requests.except... 1042s FAILED tests/test_offsets.py::test_basic_offsets - requests.exceptions.Connec... 1042s FAILED tests/test_pickle.py::test_pickle - requests.exceptions.ConnectionErro... 1042s FAILED tests/test_simple_public.py::test_simple - requests.exceptions.Connect... 1042s FAILED tests/test_simple_public.py::test_encoding_for_model - requests.except... 1042s =================== 28 failed, 2 passed in 584.48s (0:09:44) =================== 1042s ============================= test session starts ============================== 1042s platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 1042s rootdir: /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build 1042s configfile: pyproject.toml 1042s plugins: typeguard-4.4.1, hypothesis-6.119.3 1042s collected 30 items 1042s 1070s tests/test_encoding.py FFFFFFFFFFFFFFFFFFFFFF [ 73%] 1070s tests/test_misc.py F. [ 80%] 1073s tests/test_offsets.py FF [ 86%] 1075s tests/test_pickle.py F [ 90%] 1076s tests/test_simple_public.py FF. [100%] 1076s 1076s =================================== FAILURES =================================== 1076s _________________________________ test_simple __________________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_simple(): 1076s > enc = tiktoken.get_encoding("gpt2") 1076s 1076s tests/test_encoding.py:15: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1076s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1076s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s _____________________________ test_simple_repeated _____________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_simple_repeated(): 1076s > enc = tiktoken.get_encoding("gpt2") 1076s 1076s tests/test_encoding.py:32: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1076s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1076s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________________ test_simple_regex _______________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_simple_regex(): 1076s > enc = tiktoken.get_encoding("cl100k_base") 1076s 1076s tests/test_encoding.py:53: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________________ test_basic_encode _______________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_basic_encode(): 1076s > enc = tiktoken.get_encoding("r50k_base") 1076s 1076s tests/test_encoding.py:62: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________________ test_encode_empty _______________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_encode_empty(): 1076s > enc = tiktoken.get_encoding("r50k_base") 1076s 1076s tests/test_encoding.py:74: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________________ test_encode_bytes _______________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connectionE: pybuild pybuild:389: test: plugin pyproject failed with: exit code=1: cd /tmp/autopkgtest.O2gf3u/autopkgtest_tmp/build; python3.12 -m pytest tests 1076s 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_encode_bytes(): 1076s > enc = tiktoken.get_encoding("cl100k_base") 1076s 1076s tests/test_encoding.py:79: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s _________________________ test_encode_surrogate_pairs __________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s def test_encode_surrogate_pairs(): 1076s > enc = tiktoken.get_encoding("cl100k_base") 1076s 1076s tests/test_encoding.py:84: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s _________________ test_catastrophically_repetitive[r50k_base] __________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instancepybuild-autopkgtest: error: pybuild --autopkgtest --test-pytest -i python{version} -p "3.13 3.12" returned exit code 13 1076s make: *** [/tmp/gHYqKpPWG4/run:4: pybuild-autopkgtest] Error 25 1076s pybuild-autopkgtest: error: /tmp/gHYqKpPWG4/run pybuild-autopkgtest returned exit code 2 1076s 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'r50k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:96: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ________________ test_catastrophically_repetitive[cl100k_base] _________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'cl100k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:96: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s _______________________ test_basic_roundtrip[r50k_base] ________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'r50k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_basic_roundtrip(make_enc): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:115: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________ test_basic_roundtrip[cl100k_base] _______________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'cl100k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_basic_roundtrip(make_enc): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:115: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ________________________ test_hyp_roundtrip[r50k_base] _________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'r50k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s > @hypothesis.given(text=st.text()) 1076s 1076s tests/test_encoding.py:131: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s tests/test_encoding.py:134: in test_hyp_roundtrip 1076s enc = make_enc() 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s E Falsifying example: test_hyp_roundtrip( 1076s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1076s E text='', 1076s E ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s _______________________ test_hyp_roundtrip[cl100k_base] ________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'cl100k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s > @hypothesis.given(text=st.text()) 1076s 1076s tests/test_encoding.py:131: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s tests/test_encoding.py:134: in test_hyp_roundtrip 1076s enc = make_enc() 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s E Falsifying example: test_hyp_roundtrip( 1076s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1076s E text='', 1076s E ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ____________________ test_single_token_roundtrip[r50k_base] ____________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'r50k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:141: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ___________________ test_single_token_roundtrip[cl100k_base] ___________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1076s Get a connection from the pool and perform an HTTP request. This is the 1076s lowest level call for making a request, so you'll need to specify all 1076s the raw details. 1076s 1076s .. note:: 1076s 1076s More commonly, it's appropriate to use a convenience method 1076s such as :meth:`request`. 1076s 1076s .. note:: 1076s 1076s `release_conn` will only behave as expected if 1076s `preload_content=False` because we want to make 1076s `preload_content=False` the default behaviour someday soon without 1076s breaking backwards compatibility. 1076s 1076s :param method: 1076s HTTP request method (such as GET, POST, PUT, etc.) 1076s 1076s :param url: 1076s The URL to perform the request on. 1076s 1076s :param body: 1076s Data to send in the request body, either :class:`str`, :class:`bytes`, 1076s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1076s 1076s :param headers: 1076s Dictionary of custom headers to send, such as User-Agent, 1076s If-None-Match, etc. If None, pool headers are used. If provided, 1076s these headers completely replace any pool-specific headers. 1076s 1076s :param retries: 1076s Configure the number of retries to allow before raising a 1076s :class:`~urllib3.exceptions.MaxRetryError` exception. 1076s 1076s Pass ``None`` to retry until you receive a response. Pass a 1076s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1076s over different types of retries. 1076s Pass an integer number to retry connection errors that many times, 1076s but no other types of errors. Pass zero to never retry. 1076s 1076s If ``False``, then retries are disabled and any exception is raised 1076s immediately. Also, instead of raising a MaxRetryError on redirects, 1076s the redirect response will be returned. 1076s 1076s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1076s 1076s :param redirect: 1076s If True, automatically handle redirects (status codes 301, 302, 1076s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1076s will disable redirect, too. 1076s 1076s :param assert_same_host: 1076s If ``True``, will make sure that the host of the pool requests is 1076s consistent else will raise HostChangedError. When ``False``, you can 1076s use the pool on an HTTP proxy and request foreign hosts. 1076s 1076s :param timeout: 1076s If specified, overrides the default timeout for this one 1076s request. It may be a float (in seconds) or an instance of 1076s :class:`urllib3.util.Timeout`. 1076s 1076s :param pool_timeout: 1076s If set and the pool is set to block=True, then this method will 1076s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1076s connection is available within the time period. 1076s 1076s :param bool preload_content: 1076s If True, the response's body will be preloaded into memory. 1076s 1076s :param bool decode_content: 1076s If True, will attempt to decode the body based on the 1076s 'content-encoding' header. 1076s 1076s :param release_conn: 1076s If False, then the urlopen call will not release the connection 1076s back into the pool once a response is received (but will release if 1076s you read the entire contents of the response such as when 1076s `preload_content=True`). This is useful if you're not preloading 1076s the response's content immediately. You will need to call 1076s ``r.release_conn()`` on the response ``r`` to return the connection 1076s back into the pool. If None, it takes the value of ``preload_content`` 1076s which defaults to ``True``. 1076s 1076s :param bool chunked: 1076s If True, urllib3 will send the body using chunked transfer 1076s encoding. Otherwise, urllib3 will send the body using the standard 1076s content-length form. Defaults to False. 1076s 1076s :param int body_pos: 1076s Position to seek to in file-like body in the event of a retry or 1076s redirect. Typically this won't need to be set because urllib3 will 1076s auto-populate the value when needed. 1076s """ 1076s parsed_url = parse_url(url) 1076s destination_scheme = parsed_url.scheme 1076s 1076s if headers is None: 1076s headers = self.headers 1076s 1076s if not isinstance(retries, Retry): 1076s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1076s 1076s if release_conn is None: 1076s release_conn = preload_content 1076s 1076s # Check host 1076s if assert_same_host and not self.is_same_host(url): 1076s raise HostChangedError(self, url, retries) 1076s 1076s # Ensure that the URL we're connecting to is properly encoded 1076s if url.startswith("/"): 1076s url = to_str(_encode_target(url)) 1076s else: 1076s url = to_str(parsed_url.url) 1076s 1076s conn = None 1076s 1076s # Track whether `conn` needs to be released before 1076s # returning/raising/recursing. Update this variable if necessary, and 1076s # leave `release_conn` constant throughout the function. That way, if 1076s # the function recurses, the original value of `release_conn` will be 1076s # passed down into the recursive call, and its value will be respected. 1076s # 1076s # See issue #651 [1] for details. 1076s # 1076s # [1] 1076s release_this_conn = release_conn 1076s 1076s http_tunnel_required = connection_requires_http_tunnel( 1076s self.proxy, self.proxy_config, destination_scheme 1076s ) 1076s 1076s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1076s # have to copy the headers dict so we can safely change it without those 1076s # changes being reflected in anyone else's copy. 1076s if not http_tunnel_required: 1076s headers = headers.copy() # type: ignore[attr-defined] 1076s headers.update(self.proxy_headers) # type: ignore[union-attr] 1076s 1076s # Must keep the exception bound to a separate variable or else Python 3 1076s # complains about UnboundLocalError. 1076s err = None 1076s 1076s # Keep track of whether we cleanly exited the except block. This 1076s # ensures we do proper cleanup in finally. 1076s clean_exit = False 1076s 1076s # Rewind body position, if needed. Record current position 1076s # for future rewinds in the event of a redirect/retry. 1076s body_pos = set_file_position(body, body_pos) 1076s 1076s try: 1076s # Request a connection from the queue. 1076s timeout_obj = self._get_timeout(timeout) 1076s conn = self._get_conn(timeout=pool_timeout) 1076s 1076s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1076s 1076s # Is this a closed/new connection that requires CONNECT tunnelling? 1076s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1076s try: 1076s self._prepare_proxy(conn) 1076s except (BaseSSLError, OSError, SocketTimeout) as e: 1076s self._raise_timeout( 1076s err=e, url=self.proxy.url, timeout_value=conn.timeout 1076s ) 1076s raise 1076s 1076s # If we're going to release the connection in ``finally:``, then 1076s # the response doesn't need to know about the connection. Otherwise 1076s # it will also try to release it and we'll have a double-release 1076s # mess. 1076s response_conn = conn if not release_conn else None 1076s 1076s # Make the request on the HTTPConnection object 1076s > response = self._make_request( 1076s conn, 1076s method, 1076s url, 1076s timeout=timeout_obj, 1076s body=body, 1076s headers=headers, 1076s chunked=chunked, 1076s retries=retries, 1076s response_conn=response_conn, 1076s preload_content=preload_content, 1076s decode_content=decode_content, 1076s **response_kw, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1076s raise new_e 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1076s self._validate_conn(conn) 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1076s conn.connect() 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1076s self.sock = sock = self._new_conn() 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s except socket.gaierror as e: 1076s raise NameResolutionError(self.host, self, e) from e 1076s except SocketTimeout as e: 1076s raise ConnectTimeoutError( 1076s self, 1076s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1076s ) from e 1076s 1076s except OSError as e: 1076s > raise NewConnectionError( 1076s self, f"Failed to establish a new connection: {e}" 1076s ) from e 1076s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s > resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1076s retries = retries.increment( 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1076s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1076s _pool = 1076s _stacktrace = 1076s 1076s def increment( 1076s self, 1076s method: str | None = None, 1076s url: str | None = None, 1076s response: BaseHTTPResponse | None = None, 1076s error: Exception | None = None, 1076s _pool: ConnectionPool | None = None, 1076s _stacktrace: TracebackType | None = None, 1076s ) -> Retry: 1076s """Return a new Retry object with incremented retry counters. 1076s 1076s :param response: A response object, or None, if the server did not 1076s return a response. 1076s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1076s :param Exception error: An error encountered during the request, or 1076s None if the response was received successfully. 1076s 1076s :return: A new ``Retry`` object. 1076s """ 1076s if self.total is False and error: 1076s # Disabled, indicate to re-raise the error. 1076s raise reraise(type(error), error, _stacktrace) 1076s 1076s total = self.total 1076s if total is not None: 1076s total -= 1 1076s 1076s connect = self.connect 1076s read = self.read 1076s redirect = self.redirect 1076s status_count = self.status 1076s other = self.other 1076s cause = "unknown" 1076s status = None 1076s redirect_location = None 1076s 1076s if error and self._is_connection_error(error): 1076s # Connect retry? 1076s if connect is False: 1076s raise reraise(type(error), error, _stacktrace) 1076s elif connect is not None: 1076s connect -= 1 1076s 1076s elif error and self._is_read_error(error): 1076s # Read retry? 1076s if read is False or method is None or not self._is_method_retryable(method): 1076s raise reraise(type(error), error, _stacktrace) 1076s elif read is not None: 1076s read -= 1 1076s 1076s elif error: 1076s # Other retry? 1076s if other is not None: 1076s other -= 1 1076s 1076s elif response and response.get_redirect_location(): 1076s # Redirect retry? 1076s if redirect is not None: 1076s redirect -= 1 1076s cause = "too many redirects" 1076s response_redirect_location = response.get_redirect_location() 1076s if response_redirect_location: 1076s redirect_location = response_redirect_location 1076s status = response.status 1076s 1076s else: 1076s # Incrementing because of a server error like a 500 in 1076s # status_forcelist and the given method is in the allowed_methods 1076s cause = ResponseError.GENERIC_ERROR 1076s if response and response.status: 1076s if status_count is not None: 1076s status_count -= 1 1076s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1076s status = response.status 1076s 1076s history = self.history + ( 1076s RequestHistory(method, url, error, status, redirect_location), 1076s ) 1076s 1076s new_retry = self.new( 1076s total=total, 1076s connect=connect, 1076s read=read, 1076s redirect=redirect, 1076s status=status_count, 1076s other=other, 1076s history=history, 1076s ) 1076s 1076s if new_retry.is_exhausted(): 1076s reason = error or ResponseError(cause) 1076s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1076s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1076s 1076s During handling of the above exception, another exception occurred: 1076s 1076s make_enc = functools.partial(, 'cl100k_base') 1076s 1076s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1076s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 1076s > enc = make_enc() 1076s 1076s tests/test_encoding.py:141: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1076s enc = Encoding(**constructor()) 1076s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1076s mergeable_ranks = load_tiktoken_bpe( 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1076s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1076s contents = read_file(blobpath) 1076s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1076s resp = requests.get(blobpath) 1076s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1076s return request("get", url, params=params, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1076s return session.request(method=method, url=url, **kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1076s resp = self.send(prep, **send_kwargs) 1076s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1076s r = adapter.send(request, **kwargs) 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s self = 1076s request = , stream = False 1076s timeout = Timeout(connect=None, read=None, total=None), verify = True 1076s cert = None, proxies = OrderedDict() 1076s 1076s def send( 1076s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1076s ): 1076s """Sends PreparedRequest object. Returns Response object. 1076s 1076s :param request: The :class:`PreparedRequest ` being sent. 1076s :param stream: (optional) Whether to stream the request content. 1076s :param timeout: (optional) How long to wait for the server to send 1076s data before giving up, as a float, or a :ref:`(connect timeout, 1076s read timeout) ` tuple. 1076s :type timeout: float or tuple or urllib3 Timeout object 1076s :param verify: (optional) Either a boolean, in which case it controls whether 1076s we verify the server's TLS certificate, or a string, in which case it 1076s must be a path to a CA bundle to use 1076s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1076s :param proxies: (optional) The proxies dictionary to apply to the request. 1076s :rtype: requests.Response 1076s """ 1076s 1076s try: 1076s conn = self.get_connection_with_tls_context( 1076s request, verify, proxies=proxies, cert=cert 1076s ) 1076s except LocationValueError as e: 1076s raise InvalidURL(e, request=request) 1076s 1076s self.cert_verify(conn, request.url, verify, cert) 1076s url = self.request_url(request, proxies) 1076s self.add_headers( 1076s request, 1076s stream=stream, 1076s timeout=timeout, 1076s verify=verify, 1076s cert=cert, 1076s proxies=proxies, 1076s ) 1076s 1076s chunked = not (request.body is None or "Content-Length" in request.headers) 1076s 1076s if isinstance(timeout, tuple): 1076s try: 1076s connect, read = timeout 1076s timeout = TimeoutSauce(connect=connect, read=read) 1076s except ValueError: 1076s raise ValueError( 1076s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1076s f"or a single float to set both timeouts to the same value." 1076s ) 1076s elif isinstance(timeout, TimeoutSauce): 1076s pass 1076s else: 1076s timeout = TimeoutSauce(connect=timeout, read=timeout) 1076s 1076s try: 1076s resp = conn.urlopen( 1076s method=request.method, 1076s url=url, 1076s body=request.body, 1076s headers=request.headers, 1076s redirect=False, 1076s assert_same_host=False, 1076s preload_content=False, 1076s decode_content=False, 1076s retries=self.max_retries, 1076s timeout=timeout, 1076s chunked=chunked, 1076s ) 1076s 1076s except (ProtocolError, OSError) as err: 1076s raise ConnectionError(err, request=request) 1076s 1076s except MaxRetryError as e: 1076s if isinstance(e.reason, ConnectTimeoutError): 1076s # TODO: Remove this in 3.0.0: see #2811 1076s if not isinstance(e.reason, NewConnectionError): 1076s raise ConnectTimeout(e, request=request) 1076s 1076s if isinstance(e.reason, ResponseError): 1076s raise RetryError(e, request=request) 1076s 1076s if isinstance(e.reason, _ProxyError): 1076s raise ProxyError(e, request=request) 1076s 1076s if isinstance(e.reason, _SSLError): 1076s # This branch is for urllib3 v1.22 and later. 1076s raise SSLError(e, request=request) 1076s 1076s > raise ConnectionError(e, request=request) 1076s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1076s 1076s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1076s ______________________________ test_special_token ______________________________ 1076s 1076s self = 1076s 1076s def _new_conn(self) -> socket.socket: 1076s """Establish a socket connection and set nodelay settings on it. 1076s 1076s :return: New socket connection. 1076s """ 1076s try: 1076s > sock = connection.create_connection( 1076s (self._dns_host, self.port), 1076s self.timeout, 1076s source_address=self.source_address, 1076s socket_options=self.socket_options, 1076s ) 1076s 1076s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1076s raise err 1076s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1076s 1076s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1076s source_address = None, socket_options = [(6, 1, 1)] 1076s 1076s def create_connection( 1076s address: tuple[str, int], 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s source_address: tuple[str, int] | None = None, 1076s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1076s ) -> socket.socket: 1076s """Connect to *address* and return the socket object. 1076s 1076s Convenience function. Connect to *address* (a 2-tuple ``(host, 1076s port)``) and return the socket object. Passing the optional 1076s *timeout* parameter will set the timeout on the socket instance 1076s before attempting to connect. If no *timeout* is supplied, the 1076s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1076s is used. If *source_address* is set it must be a tuple of (host, port) 1076s for the socket to bind as a source address before making the connection. 1076s An host of '' or port 0 tells the OS to use the default. 1076s """ 1076s 1076s host, port = address 1076s if host.startswith("["): 1076s host = host.strip("[]") 1076s err = None 1076s 1076s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1076s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1076s # The original create_connection function always returns all records. 1076s family = allowed_gai_family() 1076s 1076s try: 1076s host.encode("idna") 1076s except UnicodeError: 1076s raise LocationParseError(f"'{host}', label empty or too long") from None 1076s 1076s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1076s af, socktype, proto, canonname, sa = res 1076s sock = None 1076s try: 1076s sock = socket.socket(af, socktype, proto) 1076s 1076s # If provided, set socket level options before connecting. 1076s _set_socket_options(sock, socket_options) 1076s 1076s if timeout is not _DEFAULT_TIMEOUT: 1076s sock.settimeout(timeout) 1076s if source_address: 1076s sock.bind(source_address) 1076s > sock.connect(sa) 1076s E ConnectionRefusedError: [Errno 111] Connection refused 1076s 1076s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1076s 1076s The above exception was the direct cause of the following exception: 1076s 1076s self = 1076s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1076s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1076s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1076s redirect = False, assert_same_host = False 1076s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1076s release_conn = False, chunked = False, body_pos = None, preload_content = False 1076s decode_content = False, response_kw = {} 1076s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1076s destination_scheme = None, conn = None, release_this_conn = True 1076s http_tunnel_required = False, err = None, clean_exit = False 1076s 1076s def urlopen( # type: ignore[override] 1076s self, 1076s method: str, 1076s url: str, 1076s body: _TYPE_BODY | None = None, 1076s headers: typing.Mapping[str, str] | None = None, 1076s retries: Retry | bool | int | None = None, 1076s redirect: bool = True, 1076s assert_same_host: bool = True, 1076s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1076s pool_timeout: int | None = None, 1076s release_conn: bool | None = None, 1076s chunked: bool = False, 1076s body_pos: _TYPE_BODY_POSITION | None = None, 1076s preload_content: bool = True, 1076s decode_content: bool = True, 1076s **response_kw: typing.Any, 1076s ) -> BaseHTTPResponse: 1076s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_special_token(): 1077s > enc = tiktoken.get_encoding("cl100k_base") 1077s 1077s tests/test_encoding.py:157: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s _____________________ test_hyp_special_ordinary[r50k_base] _____________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'r50k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s > @hypothesis.given(text=st.text()) 1077s 1077s tests/test_encoding.py:208: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s tests/test_encoding.py:211: in test_hyp_special_ordinary 1077s enc = make_enc() 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s E Falsifying example: test_hyp_special_ordinary( 1077s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1077s E text='', 1077s E ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ____________________ test_hyp_special_ordinary[cl100k_base] ____________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'cl100k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s > @hypothesis.given(text=st.text()) 1077s 1077s tests/test_encoding.py:208: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s tests/test_encoding.py:211: in test_hyp_special_ordinary 1077s enc = make_enc() 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s E Falsifying example: test_hyp_special_ordinary( 1077s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1077s E text='', 1077s E ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s _________________________ test_batch_encode[r50k_base] _________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'r50k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 1077s > enc = make_enc() 1077s 1077s tests/test_encoding.py:222: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ________________________ test_batch_encode[cl100k_base] ________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'cl100k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 1077s > enc = make_enc() 1077s 1077s tests/test_encoding.py:222: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s _____________________ test_hyp_batch_roundtrip[r50k_base] ______________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'r50k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s > @hypothesis.given(batch=st.lists(st.text())) 1077s 1077s tests/test_encoding.py:237: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 1077s enc = make_enc() 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s E Falsifying example: test_hyp_batch_roundtrip( 1077s E make_enc=functools.partial(get_encoding, 'r50k_base'), 1077s E batch=[], 1077s E ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ____________________ test_hyp_batch_roundtrip[cl100k_base] _____________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'cl100k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 1077s > @hypothesis.given(batch=st.lists(st.text())) 1077s 1077s tests/test_encoding.py:237: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 1077s enc = make_enc() 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s E Falsifying example: test_hyp_batch_roundtrip( 1077s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1077s E batch=[], 1077s E ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ___________________________ test_encoding_for_model ____________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_encoding_for_model(): 1077s > enc = tiktoken.encoding_for_model("gpt2") 1077s 1077s tests/test_misc.py:8: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 1077s return get_encoding(encoding_name_for_model(model_name)) 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1077s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1077s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ________________________ test_hyp_offsets[cl100k_base] _________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s make_enc = functools.partial(, 'cl100k_base') 1077s 1077s @pytest.mark.parametrize("make_enc", SOME_ENCODING_FACTORIES) 1077s > @hypothesis.given(data=st.data()) 1077s 1077s tests/test_offsets.py:29: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s tests/test_offsets.py:32: in test_hyp_offsets 1077s enc = make_enc() 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s E Falsifying example: test_hyp_offsets( 1077s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 1077s E data=data(...), 1077s E ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ______________________________ test_basic_offsets ______________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_basic_offsets(): 1077s > enc = tiktoken.get_encoding("cl100k_base") 1077s 1077s tests/test_offsets.py:50: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s _________________________________ test_pickle __________________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_pickle(): 1077s import pickle 1077s 1077s > enc_old = tiktoken.get_encoding("r50k_base") 1077s 1077s tests/test_pickle.py:7: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 1077s mergeable_ranks = load_tiktoken_bpe( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 1077s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/r50k_base.tiktoken (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s _________________________________ test_simple __________________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_simple(): 1077s # Note that there are more actual tests, they're just not currently public :-) 1077s > enc = tiktoken.get_encoding("gpt2") 1077s 1077s tests/test_simple_public.py:9: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1077s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1077s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s ___________________________ test_encoding_for_model ____________________________ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s > sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 1077s raise err 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 1077s source_address = None, socket_options = [(6, 1, 1)] 1077s 1077s def create_connection( 1077s address: tuple[str, int], 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s source_address: tuple[str, int] | None = None, 1077s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 1077s ) -> socket.socket: 1077s """Connect to *address* and return the socket object. 1077s 1077s Convenience function. Connect to *address* (a 2-tuple ``(host, 1077s port)``) and return the socket object. Passing the optional 1077s *timeout* parameter will set the timeout on the socket instance 1077s before attempting to connect. If no *timeout* is supplied, the 1077s global default timeout setting returned by :func:`socket.getdefaulttimeout` 1077s is used. If *source_address* is set it must be a tuple of (host, port) 1077s for the socket to bind as a source address before making the connection. 1077s An host of '' or port 0 tells the OS to use the default. 1077s """ 1077s 1077s host, port = address 1077s if host.startswith("["): 1077s host = host.strip("[]") 1077s err = None 1077s 1077s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 1077s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 1077s # The original create_connection function always returns all records. 1077s family = allowed_gai_family() 1077s 1077s try: 1077s host.encode("idna") 1077s except UnicodeError: 1077s raise LocationParseError(f"'{host}', label empty or too long") from None 1077s 1077s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 1077s af, socktype, proto, canonname, sa = res 1077s sock = None 1077s try: 1077s sock = socket.socket(af, socktype, proto) 1077s 1077s # If provided, set socket level options before connecting. 1077s _set_socket_options(sock, socket_options) 1077s 1077s if timeout is not _DEFAULT_TIMEOUT: 1077s sock.settimeout(timeout) 1077s if source_address: 1077s sock.bind(source_address) 1077s > sock.connect(sa) 1077s E ConnectionRefusedError: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 1077s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 1077s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s redirect = False, assert_same_host = False 1077s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 1077s release_conn = False, chunked = False, body_pos = None, preload_content = False 1077s decode_content = False, response_kw = {} 1077s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 1077s destination_scheme = None, conn = None, release_this_conn = True 1077s http_tunnel_required = False, err = None, clean_exit = False 1077s 1077s def urlopen( # type: ignore[override] 1077s self, 1077s method: str, 1077s url: str, 1077s body: _TYPE_BODY | None = None, 1077s headers: typing.Mapping[str, str] | None = None, 1077s retries: Retry | bool | int | None = None, 1077s redirect: bool = True, 1077s assert_same_host: bool = True, 1077s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 1077s pool_timeout: int | None = None, 1077s release_conn: bool | None = None, 1077s chunked: bool = False, 1077s body_pos: _TYPE_BODY_POSITION | None = None, 1077s preload_content: bool = True, 1077s decode_content: bool = True, 1077s **response_kw: typing.Any, 1077s ) -> BaseHTTPResponse: 1077s """ 1077s Get a connection from the pool and perform an HTTP request. This is the 1077s lowest level call for making a request, so you'll need to specify all 1077s the raw details. 1077s 1077s .. note:: 1077s 1077s More commonly, it's appropriate to use a convenience method 1077s such as :meth:`request`. 1077s 1077s .. note:: 1077s 1077s `release_conn` will only behave as expected if 1077s `preload_content=False` because we want to make 1077s `preload_content=False` the default behaviour someday soon without 1077s breaking backwards compatibility. 1077s 1077s :param method: 1077s HTTP request method (such as GET, POST, PUT, etc.) 1077s 1077s :param url: 1077s The URL to perform the request on. 1077s 1077s :param body: 1077s Data to send in the request body, either :class:`str`, :class:`bytes`, 1077s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 1077s 1077s :param headers: 1077s Dictionary of custom headers to send, such as User-Agent, 1077s If-None-Match, etc. If None, pool headers are used. If provided, 1077s these headers completely replace any pool-specific headers. 1077s 1077s :param retries: 1077s Configure the number of retries to allow before raising a 1077s :class:`~urllib3.exceptions.MaxRetryError` exception. 1077s 1077s Pass ``None`` to retry until you receive a response. Pass a 1077s :class:`~urllib3.util.retry.Retry` object for fine-grained control 1077s over different types of retries. 1077s Pass an integer number to retry connection errors that many times, 1077s but no other types of errors. Pass zero to never retry. 1077s 1077s If ``False``, then retries are disabled and any exception is raised 1077s immediately. Also, instead of raising a MaxRetryError on redirects, 1077s the redirect response will be returned. 1077s 1077s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 1077s 1077s :param redirect: 1077s If True, automatically handle redirects (status codes 301, 302, 1077s 303, 307, 308). Each redirect counts as a retry. Disabling retries 1077s will disable redirect, too. 1077s 1077s :param assert_same_host: 1077s If ``True``, will make sure that the host of the pool requests is 1077s consistent else will raise HostChangedError. When ``False``, you can 1077s use the pool on an HTTP proxy and request foreign hosts. 1077s 1077s :param timeout: 1077s If specified, overrides the default timeout for this one 1077s request. It may be a float (in seconds) or an instance of 1077s :class:`urllib3.util.Timeout`. 1077s 1077s :param pool_timeout: 1077s If set and the pool is set to block=True, then this method will 1077s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 1077s connection is available within the time period. 1077s 1077s :param bool preload_content: 1077s If True, the response's body will be preloaded into memory. 1077s 1077s :param bool decode_content: 1077s If True, will attempt to decode the body based on the 1077s 'content-encoding' header. 1077s 1077s :param release_conn: 1077s If False, then the urlopen call will not release the connection 1077s back into the pool once a response is received (but will release if 1077s you read the entire contents of the response such as when 1077s `preload_content=True`). This is useful if you're not preloading 1077s the response's content immediately. You will need to call 1077s ``r.release_conn()`` on the response ``r`` to return the connection 1077s back into the pool. If None, it takes the value of ``preload_content`` 1077s which defaults to ``True``. 1077s 1077s :param bool chunked: 1077s If True, urllib3 will send the body using chunked transfer 1077s encoding. Otherwise, urllib3 will send the body using the standard 1077s content-length form. Defaults to False. 1077s 1077s :param int body_pos: 1077s Position to seek to in file-like body in the event of a retry or 1077s redirect. Typically this won't need to be set because urllib3 will 1077s auto-populate the value when needed. 1077s """ 1077s parsed_url = parse_url(url) 1077s destination_scheme = parsed_url.scheme 1077s 1077s if headers is None: 1077s headers = self.headers 1077s 1077s if not isinstance(retries, Retry): 1077s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 1077s 1077s if release_conn is None: 1077s release_conn = preload_content 1077s 1077s # Check host 1077s if assert_same_host and not self.is_same_host(url): 1077s raise HostChangedError(self, url, retries) 1077s 1077s # Ensure that the URL we're connecting to is properly encoded 1077s if url.startswith("/"): 1077s url = to_str(_encode_target(url)) 1077s else: 1077s url = to_str(parsed_url.url) 1077s 1077s conn = None 1077s 1077s # Track whether `conn` needs to be released before 1077s # returning/raising/recursing. Update this variable if necessary, and 1077s # leave `release_conn` constant throughout the function. That way, if 1077s # the function recurses, the original value of `release_conn` will be 1077s # passed down into the recursive call, and its value will be respected. 1077s # 1077s # See issue #651 [1] for details. 1077s # 1077s # [1] 1077s release_this_conn = release_conn 1077s 1077s http_tunnel_required = connection_requires_http_tunnel( 1077s self.proxy, self.proxy_config, destination_scheme 1077s ) 1077s 1077s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 1077s # have to copy the headers dict so we can safely change it without those 1077s # changes being reflected in anyone else's copy. 1077s if not http_tunnel_required: 1077s headers = headers.copy() # type: ignore[attr-defined] 1077s headers.update(self.proxy_headers) # type: ignore[union-attr] 1077s 1077s # Must keep the exception bound to a separate variable or else Python 3 1077s # complains about UnboundLocalError. 1077s err = None 1077s 1077s # Keep track of whether we cleanly exited the except block. This 1077s # ensures we do proper cleanup in finally. 1077s clean_exit = False 1077s 1077s # Rewind body position, if needed. Record current position 1077s # for future rewinds in the event of a redirect/retry. 1077s body_pos = set_file_position(body, body_pos) 1077s 1077s try: 1077s # Request a connection from the queue. 1077s timeout_obj = self._get_timeout(timeout) 1077s conn = self._get_conn(timeout=pool_timeout) 1077s 1077s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 1077s 1077s # Is this a closed/new connection that requires CONNECT tunnelling? 1077s if self.proxy is not None and http_tunnel_required and conn.is_closed: 1077s try: 1077s self._prepare_proxy(conn) 1077s except (BaseSSLError, OSError, SocketTimeout) as e: 1077s self._raise_timeout( 1077s err=e, url=self.proxy.url, timeout_value=conn.timeout 1077s ) 1077s raise 1077s 1077s # If we're going to release the connection in ``finally:``, then 1077s # the response doesn't need to know about the connection. Otherwise 1077s # it will also try to release it and we'll have a double-release 1077s # mess. 1077s response_conn = conn if not release_conn else None 1077s 1077s # Make the request on the HTTPConnection object 1077s > response = self._make_request( 1077s conn, 1077s method, 1077s url, 1077s timeout=timeout_obj, 1077s body=body, 1077s headers=headers, 1077s chunked=chunked, 1077s retries=retries, 1077s response_conn=response_conn, 1077s preload_content=preload_content, 1077s decode_content=decode_content, 1077s **response_kw, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 1077s raise new_e 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 1077s self._validate_conn(conn) 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 1077s conn.connect() 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 1077s self.sock = sock = self._new_conn() 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s 1077s def _new_conn(self) -> socket.socket: 1077s """Establish a socket connection and set nodelay settings on it. 1077s 1077s :return: New socket connection. 1077s """ 1077s try: 1077s sock = connection.create_connection( 1077s (self._dns_host, self.port), 1077s self.timeout, 1077s source_address=self.source_address, 1077s socket_options=self.socket_options, 1077s ) 1077s except socket.gaierror as e: 1077s raise NameResolutionError(self.host, self, e) from e 1077s except SocketTimeout as e: 1077s raise ConnectTimeoutError( 1077s self, 1077s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 1077s ) from e 1077s 1077s except OSError as e: 1077s > raise NewConnectionError( 1077s self, f"Failed to establish a new connection: {e}" 1077s ) from e 1077s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 1077s 1077s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 1077s 1077s The above exception was the direct cause of the following exception: 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s > resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:667: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 1077s retries = retries.increment( 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 1077s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 1077s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 1077s _pool = 1077s _stacktrace = 1077s 1077s def increment( 1077s self, 1077s method: str | None = None, 1077s url: str | None = None, 1077s response: BaseHTTPResponse | None = None, 1077s error: Exception | None = None, 1077s _pool: ConnectionPool | None = None, 1077s _stacktrace: TracebackType | None = None, 1077s ) -> Retry: 1077s """Return a new Retry object with incremented retry counters. 1077s 1077s :param response: A response object, or None, if the server did not 1077s return a response. 1077s :type response: :class:`~urllib3.response.BaseHTTPResponse` 1077s :param Exception error: An error encountered during the request, or 1077s None if the response was received successfully. 1077s 1077s :return: A new ``Retry`` object. 1077s """ 1077s if self.total is False and error: 1077s # Disabled, indicate to re-raise the error. 1077s raise reraise(type(error), error, _stacktrace) 1077s 1077s total = self.total 1077s if total is not None: 1077s total -= 1 1077s 1077s connect = self.connect 1077s read = self.read 1077s redirect = self.redirect 1077s status_count = self.status 1077s other = self.other 1077s cause = "unknown" 1077s status = None 1077s redirect_location = None 1077s 1077s if error and self._is_connection_error(error): 1077s # Connect retry? 1077s if connect is False: 1077s raise reraise(type(error), error, _stacktrace) 1077s elif connect is not None: 1077s connect -= 1 1077s 1077s elif error and self._is_read_error(error): 1077s # Read retry? 1077s if read is False or method is None or not self._is_method_retryable(method): 1077s raise reraise(type(error), error, _stacktrace) 1077s elif read is not None: 1077s read -= 1 1077s 1077s elif error: 1077s # Other retry? 1077s if other is not None: 1077s other -= 1 1077s 1077s elif response and response.get_redirect_location(): 1077s # Redirect retry? 1077s if redirect is not None: 1077s redirect -= 1 1077s cause = "too many redirects" 1077s response_redirect_location = response.get_redirect_location() 1077s if response_redirect_location: 1077s redirect_location = response_redirect_location 1077s status = response.status 1077s 1077s else: 1077s # Incrementing because of a server error like a 500 in 1077s # status_forcelist and the given method is in the allowed_methods 1077s cause = ResponseError.GENERIC_ERROR 1077s if response and response.status: 1077s if status_count is not None: 1077s status_count -= 1 1077s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 1077s status = response.status 1077s 1077s history = self.history + ( 1077s RequestHistory(method, url, error, status, redirect_location), 1077s ) 1077s 1077s new_retry = self.new( 1077s total=total, 1077s connect=connect, 1077s read=read, 1077s redirect=redirect, 1077s status=status_count, 1077s other=other, 1077s history=history, 1077s ) 1077s 1077s if new_retry.is_exhausted(): 1077s reason = error or ResponseError(cause) 1077s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 1077s E urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 1077s 1077s During handling of the above exception, another exception occurred: 1077s 1077s def test_encoding_for_model(): 1077s > enc = tiktoken.encoding_for_model("gpt2") 1077s 1077s tests/test_simple_public.py:26: 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 1077s return get_encoding(encoding_name_for_model(model_name)) 1077s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 1077s enc = Encoding(**constructor()) 1077s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 1077s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 1077s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 1077s contents = read_file(blobpath) 1077s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 1077s resp = requests.get(blobpath) 1077s /usr/lib/python3/dist-packages/requests/api.py:73: in get 1077s return request("get", url, params=params, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/api.py:59: in request 1077s return session.request(method=method, url=url, **kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 1077s resp = self.send(prep, **send_kwargs) 1077s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 1077s r = adapter.send(request, **kwargs) 1077s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1077s 1077s self = 1077s request = , stream = False 1077s timeout = Timeout(connect=None, read=None, total=None), verify = True 1077s cert = None, proxies = OrderedDict() 1077s 1077s def send( 1077s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 1077s ): 1077s """Sends PreparedRequest object. Returns Response object. 1077s 1077s :param request: The :class:`PreparedRequest ` being sent. 1077s :param stream: (optional) Whether to stream the request content. 1077s :param timeout: (optional) How long to wait for the server to send 1077s data before giving up, as a float, or a :ref:`(connect timeout, 1077s read timeout) ` tuple. 1077s :type timeout: float or tuple or urllib3 Timeout object 1077s :param verify: (optional) Either a boolean, in which case it controls whether 1077s we verify the server's TLS certificate, or a string, in which case it 1077s must be a path to a CA bundle to use 1077s :param cert: (optional) Any user-provided SSL certificate to be trusted. 1077s :param proxies: (optional) The proxies dictionary to apply to the request. 1077s :rtype: requests.Response 1077s """ 1077s 1077s try: 1077s conn = self.get_connection_with_tls_context( 1077s request, verify, proxies=proxies, cert=cert 1077s ) 1077s except LocationValueError as e: 1077s raise InvalidURL(e, request=request) 1077s 1077s self.cert_verify(conn, request.url, verify, cert) 1077s url = self.request_url(request, proxies) 1077s self.add_headers( 1077s request, 1077s stream=stream, 1077s timeout=timeout, 1077s verify=verify, 1077s cert=cert, 1077s proxies=proxies, 1077s ) 1077s 1077s chunked = not (request.body is None or "Content-Length" in request.headers) 1077s 1077s if isinstance(timeout, tuple): 1077s try: 1077s connect, read = timeout 1077s timeout = TimeoutSauce(connect=connect, read=read) 1077s except ValueError: 1077s raise ValueError( 1077s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 1077s f"or a single float to set both timeouts to the same value." 1077s ) 1077s elif isinstance(timeout, TimeoutSauce): 1077s pass 1077s else: 1077s timeout = TimeoutSauce(connect=timeout, read=timeout) 1077s 1077s try: 1077s resp = conn.urlopen( 1077s method=request.method, 1077s url=url, 1077s body=request.body, 1077s headers=request.headers, 1077s redirect=False, 1077s assert_same_host=False, 1077s preload_content=False, 1077s decode_content=False, 1077s retries=self.max_retries, 1077s timeout=timeout, 1077s chunked=chunked, 1077s ) 1077s 1077s except (ProtocolError, OSError) as err: 1077s raise ConnectionError(err, request=request) 1077s 1077s except MaxRetryError as e: 1077s if isinstance(e.reason, ConnectTimeoutError): 1077s # TODO: Remove this in 3.0.0: see #2811 1077s if not isinstance(e.reason, NewConnectionError): 1077s raise ConnectTimeout(e, request=request) 1077s 1077s if isinstance(e.reason, ResponseError): 1077s raise RetryError(e, request=request) 1077s 1077s if isinstance(e.reason, _ProxyError): 1077s raise ProxyError(e, request=request) 1077s 1077s if isinstance(e.reason, _SSLError): 1077s # This branch is for urllib3 v1.22 and later. 1077s raise SSLError(e, request=request) 1077s 1077s > raise ConnectionError(e, request=request) 1077s E requests.exceptions.ConnectionError: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /gpt-2/encodings/main/vocab.bpe (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused')) 1077s 1077s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 1077s =========================== short test summary info ============================ 1077s FAILED tests/test_encoding.py::test_simple - requests.exceptions.ConnectionEr... 1077s FAILED tests/test_encoding.py::test_simple_repeated - requests.exceptions.Con... 1077s FAILED tests/test_encoding.py::test_simple_regex - requests.exceptions.Connec... 1077s FAILED tests/test_encoding.py::test_basic_encode - requests.exceptions.Connec... 1077s FAILED tests/test_encoding.py::test_encode_empty - requests.exceptions.Connec... 1077s FAILED tests/test_encoding.py::test_encode_bytes - requests.exceptions.Connec... 1077s FAILED tests/test_encoding.py::test_encode_surrogate_pairs - requests.excepti... 1077s FAILED tests/test_encoding.py::test_catastrophically_repetitive[r50k_base] - ... 1077s FAILED tests/test_encoding.py::test_catastrophically_repetitive[cl100k_base] 1077s FAILED tests/test_encoding.py::test_basic_roundtrip[r50k_base] - requests.exc... 1077s FAILED tests/test_encoding.py::test_basic_roundtrip[cl100k_base] - requests.e... 1077s FAILED tests/test_encoding.py::test_hyp_roundtrip[r50k_base] - requests.excep... 1077s FAILED tests/test_encoding.py::test_hyp_roundtrip[cl100k_base] - requests.exc... 1077s FAILED tests/test_encoding.py::test_single_token_roundtrip[r50k_base] - reque... 1077s FAILED tests/test_encoding.py::test_single_token_roundtrip[cl100k_base] - req... 1077s FAILED tests/test_encoding.py::test_special_token - requests.exceptions.Conne... 1077s FAILED tests/test_encoding.py::test_hyp_special_ordinary[r50k_base] - request... 1077s FAILED tests/test_encoding.py::test_hyp_special_ordinary[cl100k_base] - reque... 1077s FAILED tests/test_encoding.py::test_batch_encode[r50k_base] - requests.except... 1077s FAILED tests/test_encoding.py::test_batch_encode[cl100k_base] - requests.exce... 1077s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[r50k_base] - requests... 1077s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[cl100k_base] - reques... 1077s FAILED tests/test_misc.py::test_encoding_for_model - requests.exceptions.Conn... 1077s FAILED tests/test_offsets.py::test_hyp_offsets[cl100k_base] - requests.except... 1077s FAILED tests/test_offsets.py::test_basic_offsets - requests.exceptions.Connec... 1077s FAILED tests/test_pickle.py::test_pickle - requests.exceptions.ConnectionErro... 1077s FAILED tests/test_simple_public.py::test_simple - requests.exceptions.Connect... 1077s FAILED tests/test_simple_public.py::test_encoding_for_model - requests.except... 1077s ======================== 28 failed, 2 passed in 34.34s ========================= 1077s autopkgtest [09:52:54]: test pybuild-autopkgtest: -----------------------] 1086s autopkgtest [09:53:03]: test pybuild-autopkgtest: - - - - - - - - - - results - - - - - - - - - - 1086s pybuild-autopkgtest FAIL non-zero exit status 25 1094s autopkgtest [09:53:11]: @@@@@@@@@@@@@@@@@@@@ summary 1094s pybuild-autopkgtest FAIL non-zero exit status 25