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-2; command line: /home/ubuntu/autopkgtest/runner/autopkgtest --output-dir /tmp/autopkgtest-work._7k26kn8/out --timeout-copy=6000 --setup-commands /home/ubuntu/autopkgtest-cloud/worker-config-production/setup-canonical.sh --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' -- ssh -s /home/ubuntu/autopkgtest/ssh-setup/nova -- --flavor autopkgtest --security-groups autopkgtest-juju-7f2275-prod-proposed-migration-environment-2@bos03-arm64-20.secgroup --name adt-plucky-arm64-tiktoken-20241203-093457-juju-7f2275-prod-proposed-migration-environment-2-d114b136-f376-4b9b-991c-5b6e8cc4b8f1 --image adt/ubuntu-plucky-arm64-server --keyname testbed-juju-7f2275-prod-proposed-migration-environment-2 --net-id=net_prod-proposed-migration -e TERM=linux -e ''"'"'http_proxy=http://squid.internal:3128'"'"'' -e ''"'"'https_proxy=http://squid.internal:3128'"'"'' -e ''"'"'no_proxy=127.0.0.1,127.0.1.1,login.ubuntu.com,localhost,localdomain,novalocal,internal,archive.ubuntu.com,ports.ubuntu.com,security.ubuntu.com,ddebs.ubuntu.com,changelogs.ubuntu.com,keyserver.ubuntu.com,launchpadlibrarian.net,launchpadcontent.net,launchpad.net,10.24.0.0/24,keystone.ps5.canonical.com,objectstorage.prodstack5.canonical.com'"'"'' --mirror=http://ftpmaster.internal/ubuntu/ 161s autopkgtest [09:37:38]: testbed dpkg architecture: arm64 161s autopkgtest [09:37:38]: testbed apt version: 2.9.14ubuntu1 162s autopkgtest [09:37:39]: @@@@@@@@@@@@@@@@@@@@ test bed setup 162s autopkgtest [09:37:39]: testbed release detected to be: None 163s autopkgtest [09:37:40]: updating testbed package index (apt update) 164s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed InRelease [73.9 kB] 164s Hit:2 http://ftpmaster.internal/ubuntu plucky InRelease 164s Hit:3 http://ftpmaster.internal/ubuntu plucky-updates InRelease 164s Hit:4 http://ftpmaster.internal/ubuntu plucky-security InRelease 164s Get:5 http://ftpmaster.internal/ubuntu plucky-proposed/universe Sources [781 kB] 164s Get:6 http://ftpmaster.internal/ubuntu plucky-proposed/restricted Sources [9708 B] 164s Get:7 http://ftpmaster.internal/ubuntu plucky-proposed/multiverse Sources [15.1 kB] 164s Get:8 http://ftpmaster.internal/ubuntu plucky-proposed/main Sources [65.3 kB] 164s Get:9 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 Packages [145 kB] 164s Get:10 http://ftpmaster.internal/ubuntu plucky-proposed/restricted arm64 Packages [58.2 kB] 164s Get:11 http://ftpmaster.internal/ubuntu plucky-proposed/universe arm64 Packages [669 kB] 164s Get:12 http://ftpmaster.internal/ubuntu plucky-proposed/multiverse arm64 Packages [21.3 kB] 165s Fetched 1838 kB in 1s (1807 kB/s) 166s Reading package lists... 166s Reading package lists... 167s Building dependency tree... 167s Reading state information... 168s Calculating upgrade... 168s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 168s Reading package lists... 169s Building dependency tree... 169s Reading state information... 169s 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded. 169s autopkgtest [09:37:46]: upgrading testbed (apt dist-upgrade and autopurge) 170s Reading package lists... 170s Building dependency tree... 170s Reading state information... 171s Calculating upgrade...Starting pkgProblemResolver with broken count: 0 171s Starting 2 pkgProblemResolver with broken count: 0 171s Done 172s Entering ResolveByKeep 172s 173s The following packages will be upgraded: 173s libpython3-stdlib python3 python3-minimal 173s 3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 173s Need to get 61.4 kB of archives. 173s After this operation, 0 B of additional disk space will be used. 173s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 python3-minimal arm64 3.12.7-1 [27.4 kB] 173s Get:2 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 python3 arm64 3.12.7-1 [24.0 kB] 173s Get:3 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 libpython3-stdlib arm64 3.12.7-1 [10.0 kB] 174s Fetched 61.4 kB in 0s (211 kB/s) 174s (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 ... 80333 files and directories currently installed.) 174s Preparing to unpack .../python3-minimal_3.12.7-1_arm64.deb ... 174s Unpacking python3-minimal (3.12.7-1) over (3.12.6-0ubuntu1) ... 174s Setting up python3-minimal (3.12.7-1) ... 175s (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 ... 80333 files and directories currently installed.) 175s Preparing to unpack .../python3_3.12.7-1_arm64.deb ... 175s Unpacking python3 (3.12.7-1) over (3.12.6-0ubuntu1) ... 175s Preparing to unpack .../libpython3-stdlib_3.12.7-1_arm64.deb ... 175s Unpacking libpython3-stdlib:arm64 (3.12.7-1) over (3.12.6-0ubuntu1) ... 175s Setting up libpython3-stdlib:arm64 (3.12.7-1) ... 175s Setting up python3 (3.12.7-1) ... 175s Processing triggers for man-db (2.13.0-1) ... 176s Reading package lists... 177s Building dependency tree... 177s Reading state information... 177s Starting pkgProblemResolver with broken count: 0 177s Starting 2 pkgProblemResolver with broken count: 0 177s Done 178s 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 181s autopkgtest [09:37:58]: testbed running kernel: Linux 6.11.0-8-generic #8-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 16 14:19:41 UTC 2024 182s autopkgtest [09:37:59]: @@@@@@@@@@@@@@@@@@@@ apt-source tiktoken 184s Get:1 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (dsc) [2247 B] 184s Get:2 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (tar) [31.6 kB] 184s Get:3 http://ftpmaster.internal/ubuntu plucky-proposed/universe tiktoken 0.8.0-1build1 (diff) [3908 B] 184s gpgv: Signature made Mon Nov 18 15:38:19 2024 UTC 184s gpgv: using RSA key 25E3FF2D7F469DBE7D0D4E50AFCFEC8E669CE1C2 184s gpgv: Can't check signature: No public key 184s dpkg-source: warning: cannot verify inline signature for ./tiktoken_0.8.0-1build1.dsc: no acceptable signature found 184s autopkgtest [09:38:01]: testing package tiktoken version 0.8.0-1build1 185s autopkgtest [09:38:02]: build not needed 186s autopkgtest [09:38:03]: test pybuild-autopkgtest: preparing testbed 186s Reading package lists... 186s Building dependency tree... 186s Reading state information... 187s Starting pkgProblemResolver with broken count: 0 187s Starting 2 pkgProblemResolver with broken count: 0 187s Done 188s The following NEW packages will be installed: 188s autoconf automake autopoint autotools-dev binutils-mingw-w64-i686 188s binutils-mingw-w64-x86-64 build-essential cargo cargo-1.80 cmake cmake-data 188s cpp cpp-14 cpp-14-aarch64-linux-gnu cpp-aarch64-linux-gnu debhelper 188s debugedit dh-autoreconf dh-python dh-strip-nondeterminism dwz 188s fontconfig-config fonts-dejavu-core fonts-dejavu-mono g++ g++-14 188s g++-14-aarch64-linux-gnu g++-aarch64-linux-gnu gcc gcc-14 188s gcc-14-aarch64-linux-gnu gcc-aarch64-linux-gnu gettext intltool-debian 188s libarchive-zip-perl libasan8 libbrotli-dev libbz2-dev libcc1-0 188s libdebhelper-perl libexpat1-dev libfile-stripnondeterminism-perl 188s libfontconfig-dev libfontconfig1 libfreetype-dev libgcc-14-dev libgit2-1.7 188s libgomp1 libhttp-parser2.9 libhwasan0 libisl23 libitm1 libjsoncpp25 liblsan0 188s libmpc3 libpfm4 libpkgconf3 libpng-dev libpython3-all-dev libpython3-dev 188s libpython3.12-dev libpython3.13 libpython3.13-dev libpython3.13-minimal 188s libpython3.13-stdlib librhash0 librust-ab-glyph-dev 188s librust-ab-glyph-rasterizer+libm-dev librust-ab-glyph-rasterizer-dev 188s librust-addr2line-dev librust-adler-dev librust-ahash-dev 188s librust-aho-corasick-dev librust-allocator-api2-dev librust-anes-dev 188s librust-anstream-dev librust-anstyle-dev librust-anstyle-parse-dev 188s librust-anstyle-query-dev librust-anyhow-dev librust-approx-dev 188s librust-arbitrary-dev librust-array-init-dev librust-arrayvec-dev 188s librust-async-attributes-dev librust-async-channel-dev 188s librust-async-executor-dev librust-async-fs-dev 188s librust-async-global-executor-dev librust-async-io-dev 188s librust-async-lock-dev librust-async-net-dev librust-async-process-dev 188s librust-async-signal-dev librust-async-std-dev librust-async-task-dev 188s librust-atomic-dev librust-atomic-waker-dev librust-autocfg-dev 188s librust-backtrace-dev librust-base64-dev librust-bit-set+std-dev 188s librust-bit-set-dev librust-bit-vec-dev librust-bitflags-1-dev 188s librust-bitflags-dev librust-bitvec-dev librust-blobby-dev 188s librust-block-buffer-dev librust-blocking-dev librust-bstr-dev 188s librust-bumpalo-dev librust-bytecheck-derive-dev librust-bytecheck-dev 188s librust-bytemuck-derive-dev librust-bytemuck-dev librust-byteorder-dev 188s librust-bytes-dev librust-cast-dev librust-cc-dev librust-cfg-if-0.1-dev 188s librust-cfg-if-dev librust-chrono-dev librust-chrono-tz-build-dev 188s librust-chrono-tz-dev librust-ciborium-dev librust-ciborium-io-dev 188s librust-ciborium-ll-dev librust-clap-builder-dev librust-clap-derive-dev 188s librust-clap-dev librust-clap-lex-dev librust-cmake-dev 188s librust-color-quant-dev librust-colorchoice-dev 188s librust-compiler-builtins+core-dev 188s librust-compiler-builtins+rustc-dep-of-std-dev librust-compiler-builtins-dev 188s librust-concurrent-queue-dev librust-const-cstr-dev librust-const-oid-dev 188s librust-const-random-dev librust-const-random-macro-dev 188s librust-convert-case-dev librust-core-maths-dev librust-cpp-demangle-dev 188s librust-cpufeatures-dev librust-crc32fast-dev librust-criterion-dev 188s librust-critical-section-dev librust-crossbeam-deque-dev 188s librust-crossbeam-epoch+std-dev librust-crossbeam-epoch-dev 188s librust-crossbeam-utils-dev librust-crunchy-dev librust-crypto-common-dev 188s librust-csv-core-dev librust-csv-dev librust-ctor-dev librust-deranged-dev 188s librust-derive-arbitrary-dev librust-derive-more-0.99-dev librust-digest-dev 188s librust-dirs-next-dev librust-dirs-sys-next-dev librust-dlib-dev 188s librust-either-dev librust-env-logger-dev librust-equivalent-dev 188s librust-erased-serde-dev librust-errno-dev librust-eui48-dev 188s librust-event-listener-dev librust-event-listener-strategy-dev 188s librust-eyre+default-dev librust-eyre-dev librust-fallible-iterator-dev 188s librust-fancy-regex-dev librust-fastrand-dev librust-flate2-dev 188s librust-float-ord-dev librust-fnv-dev librust-font-kit-dev 188s librust-freetype-dev librust-freetype-sys-dev librust-funty-dev 188s librust-futures-channel-dev librust-futures-core-dev librust-futures-dev 188s librust-futures-executor-dev librust-futures-io-dev librust-futures-lite-dev 188s librust-futures-macro-dev librust-futures-sink-dev librust-futures-task-dev 188s librust-futures-util-dev librust-generic-array-dev librust-geo-types-dev 188s librust-getrandom-dev librust-ghost-dev librust-gif-dev librust-gimli-dev 188s librust-half-dev librust-hashbrown-dev librust-heck-dev librust-hmac-dev 188s librust-humantime-dev librust-iana-time-zone-dev librust-image-dev 188s librust-indenter-dev librust-indexmap-dev librust-indoc-dev 188s librust-inventory-dev librust-is-terminal-dev librust-itertools-dev 188s librust-itoa-dev librust-jobserver-dev librust-jpeg-decoder-dev 188s librust-js-sys-dev librust-kv-log-macro-dev librust-lazy-static-dev 188s librust-libc-dev librust-libloading-dev librust-libm-dev 188s librust-libwebp-sys-dev librust-libz-sys-dev librust-linux-raw-sys-dev 188s librust-lock-api-dev librust-log-dev librust-md-5-dev librust-md5-asm-dev 188s librust-memchr-dev librust-memmap2-dev librust-memoffset-dev 188s librust-miniz-oxide-dev librust-mio-dev librust-no-panic-dev 188s librust-num-bigint-dev librust-num-complex-dev librust-num-conv-dev 188s librust-num-cpus-dev librust-num-integer-dev librust-num-rational-dev 188s librust-num-threads-dev librust-num-traits-dev librust-object-dev 188s librust-once-cell-dev librust-oorandom-dev librust-owned-ttf-parser-dev 188s librust-owning-ref-dev librust-parking-dev librust-parking-lot-core-dev 188s librust-parking-lot-dev librust-parse-zoneinfo-dev 188s librust-pathfinder-geometry-dev librust-pathfinder-simd-dev 188s librust-phf+uncased-dev librust-phf-codegen-dev librust-phf-dev 188s librust-phf-generator-dev librust-phf-shared+uncased-dev 188s librust-phf-shared-dev librust-pin-project-lite-dev librust-pin-utils-dev 188s librust-pkg-config-dev librust-plotters-backend-dev 188s librust-plotters-bitmap-dev librust-plotters-dev librust-plotters-svg-dev 188s librust-png-dev librust-polling-dev librust-portable-atomic-dev 188s librust-postgres-derive-dev librust-postgres-protocol-dev 188s librust-postgres-types-dev librust-powerfmt-dev librust-powerfmt-macros-dev 188s librust-ppv-lite86-dev librust-proc-macro2-dev librust-proptest-dev 188s librust-ptr-meta-derive-dev librust-ptr-meta-dev 188s librust-pure-rust-locales-dev librust-pyo3-build-config-dev librust-pyo3-dev 188s librust-pyo3-ffi-dev librust-pyo3-macros-backend-dev librust-pyo3-macros-dev 188s librust-python3-dll-a-dev librust-qoi-dev librust-quick-error-dev 188s librust-quickcheck-dev librust-quote-dev librust-radium-dev 188s librust-rand-chacha-dev librust-rand-core+getrandom-dev 188s librust-rand-core+serde-dev librust-rand-core+std-dev librust-rand-core-dev 188s librust-rand-dev librust-rand-xorshift-dev librust-rayon-core-dev 188s librust-rayon-dev librust-regex-automata-dev librust-regex-dev 188s librust-regex-syntax-dev librust-rend-dev librust-rkyv-derive-dev 188s librust-rkyv-dev librust-rust-decimal-dev librust-rustc-demangle-dev 188s librust-rustc-hash-dev librust-rustc-std-workspace-core-dev 188s librust-rustc-version-dev librust-rustix-dev 188s librust-rusty-fork+wait-timeout-dev librust-rusty-fork-dev 188s librust-ruzstd-dev librust-ryu-dev librust-same-file-dev 188s librust-scopeguard-dev librust-seahash-dev librust-semver-dev 188s librust-serde-derive-dev librust-serde-dev librust-serde-fmt-dev 188s librust-serde-json-dev librust-serde-test-dev librust-sha1-asm-dev 188s librust-sha1-dev librust-sha2-asm-dev librust-sha2-dev librust-shlex-dev 188s librust-signal-hook-registry-dev librust-simdutf8-dev librust-siphasher-dev 188s librust-slab-dev librust-slog-dev librust-smallvec-dev librust-smol-dev 188s librust-smol-str-dev librust-socket2-dev librust-spin-dev 188s librust-stable-deref-trait-dev librust-static-assertions-dev 188s librust-stringprep-dev librust-strsim-dev librust-subtle-dev 188s librust-sval-buffer-dev librust-sval-derive-dev librust-sval-dev 188s librust-sval-dynamic-dev librust-sval-fmt-dev librust-sval-ref-dev 188s librust-sval-serde-dev librust-syn-1-dev librust-syn-dev librust-tap-dev 188s librust-target-lexicon-dev librust-tempfile-dev librust-termcolor-dev 188s librust-terminal-size-dev librust-tiff-dev librust-time-core-dev 188s librust-time-dev librust-time-macros-dev librust-tiny-keccak-dev 188s librust-tinytemplate-dev librust-tinyvec+tinyvec-macros-dev 188s librust-tinyvec-dev librust-tinyvec-macros-dev librust-tokio-dev 188s librust-tokio-macros-dev librust-tracing-attributes-dev 188s librust-tracing-core-dev librust-tracing-dev librust-traitobject-dev 188s librust-ttf-parser-dev librust-twox-hash-dev librust-typemap-dev 188s librust-typenum-dev librust-unarray-dev librust-uncased-dev 188s librust-unicase-dev librust-unicode-bidi-dev librust-unicode-ident-dev 188s librust-unicode-normalization-dev librust-unicode-segmentation-dev 188s librust-unicode-width-dev librust-unindent-dev librust-unsafe-any-dev 188s librust-utf8parse-dev librust-uuid-dev librust-valuable-derive-dev 188s librust-valuable-dev librust-value-bag-dev librust-value-bag-serde1-dev 188s librust-value-bag-sval2-dev librust-version-check-dev 188s librust-wait-timeout-dev librust-walkdir-dev 188s librust-wasm-bindgen+default-dev librust-wasm-bindgen+spans-dev 188s librust-wasm-bindgen-backend-dev librust-wasm-bindgen-dev 188s librust-wasm-bindgen-macro+spans-dev librust-wasm-bindgen-macro-dev 188s librust-wasm-bindgen-macro-support+spans-dev 188s librust-wasm-bindgen-macro-support-dev librust-wasm-bindgen-shared-dev 188s librust-web-sys-dev librust-webp-dev librust-weezl-dev librust-winapi-dev 188s librust-winapi-i686-pc-windows-gnu-dev librust-winapi-util-dev 188s librust-winapi-x86-64-pc-windows-gnu-dev librust-wyz-dev 188s librust-yeslogic-fontconfig-sys-dev librust-zerocopy-derive-dev 188s librust-zerocopy-dev librust-zeroize-derive-dev librust-zeroize-dev 188s libsharpyuv-dev libsharpyuv0 libstd-rust-1.80 libstd-rust-1.80-dev 188s libstdc++-14-dev libtool libtsan2 libubsan1 libwebp-dev libwebp7 188s libwebpdecoder3 libwebpdemux2 libwebpmux3 llvm llvm-19 llvm-19-linker-tools 188s llvm-19-runtime llvm-runtime m4 pkg-config pkgconf pkgconf-bin po-debconf 188s pybuild-plugin-autopkgtest pybuild-plugin-pyproject python3-all 188s python3-build python3-dateutil python3-hypothesis python3-iniconfig 188s python3-installer python3-packaging python3-pluggy python3-pyproject-hooks 188s python3-pytest python3-regex python3-semantic-version 188s python3-setuptools-rust python3-sortedcontainers python3-tiktoken 188s python3-toml python3-wheel python3.12-dev python3.13 python3.13-minimal 188s rustc rustc-1.80 uuid-dev zlib1g-dev 188s 0 upgraded, 472 newly installed, 0 to remove and 0 not upgraded. 188s Need to get 223 MB of archives. 188s After this operation, 945 MB of additional disk space will be used. 188s Get:1 http://ftpmaster.internal/ubuntu plucky/main arm64 libpython3.13-minimal arm64 3.13.0-2 [877 kB] 188s Get:2 http://ftpmaster.internal/ubuntu plucky/main arm64 python3.13-minimal arm64 3.13.0-2 [2100 kB] 188s Get:3 http://ftpmaster.internal/ubuntu plucky/main arm64 m4 arm64 1.4.19-4build1 [240 kB] 189s Get:4 http://ftpmaster.internal/ubuntu plucky/main arm64 autoconf all 2.72-3 [382 kB] 189s Get:5 http://ftpmaster.internal/ubuntu plucky/main arm64 autotools-dev all 20220109.1 [44.9 kB] 189s Get:6 http://ftpmaster.internal/ubuntu plucky/main arm64 automake all 1:1.16.5-1.3ubuntu1 [558 kB] 189s Get:7 http://ftpmaster.internal/ubuntu plucky/main arm64 autopoint all 0.22.5-2 [616 kB] 189s Get:8 http://ftpmaster.internal/ubuntu plucky/main arm64 libisl23 arm64 0.27-1 [676 kB] 189s Get:9 http://ftpmaster.internal/ubuntu plucky/main arm64 libmpc3 arm64 1.3.1-1build2 [56.8 kB] 189s Get:10 http://ftpmaster.internal/ubuntu plucky/main arm64 cpp-14-aarch64-linux-gnu arm64 14.2.0-9ubuntu1 [10.6 MB] 189s Get:11 http://ftpmaster.internal/ubuntu plucky/main arm64 cpp-14 arm64 14.2.0-9ubuntu1 [1030 B] 189s Get:12 http://ftpmaster.internal/ubuntu plucky/main arm64 cpp-aarch64-linux-gnu arm64 4:14.1.0-2ubuntu1 [5452 B] 189s Get:13 http://ftpmaster.internal/ubuntu plucky/main arm64 cpp arm64 4:14.1.0-2ubuntu1 [22.5 kB] 189s Get:14 http://ftpmaster.internal/ubuntu plucky/main arm64 libcc1-0 arm64 14.2.0-9ubuntu1 [49.6 kB] 189s Get:15 http://ftpmaster.internal/ubuntu plucky/main arm64 libgomp1 arm64 14.2.0-9ubuntu1 [145 kB] 189s Get:16 http://ftpmaster.internal/ubuntu plucky/main arm64 libitm1 arm64 14.2.0-9ubuntu1 [27.7 kB] 189s Get:17 http://ftpmaster.internal/ubuntu plucky/main arm64 libasan8 arm64 14.2.0-9ubuntu1 [2892 kB] 190s Get:18 http://ftpmaster.internal/ubuntu plucky/main arm64 liblsan0 arm64 14.2.0-9ubuntu1 [1283 kB] 190s Get:19 http://ftpmaster.internal/ubuntu plucky/main arm64 libtsan2 arm64 14.2.0-9ubuntu1 [2687 kB] 190s Get:20 http://ftpmaster.internal/ubuntu plucky/main arm64 libubsan1 arm64 14.2.0-9ubuntu1 [1152 kB] 190s Get:21 http://ftpmaster.internal/ubuntu plucky/main arm64 libhwasan0 arm64 14.2.0-9ubuntu1 [1599 kB] 190s Get:22 http://ftpmaster.internal/ubuntu plucky/main arm64 libgcc-14-dev arm64 14.2.0-9ubuntu1 [2594 kB] 190s Get:23 http://ftpmaster.internal/ubuntu plucky/main arm64 gcc-14-aarch64-linux-gnu arm64 14.2.0-9ubuntu1 [20.9 MB] 191s Get:24 http://ftpmaster.internal/ubuntu plucky/main arm64 gcc-14 arm64 14.2.0-9ubuntu1 [520 kB] 191s Get:25 http://ftpmaster.internal/ubuntu plucky/main arm64 gcc-aarch64-linux-gnu arm64 4:14.1.0-2ubuntu1 [1200 B] 191s Get:26 http://ftpmaster.internal/ubuntu plucky/main arm64 gcc arm64 4:14.1.0-2ubuntu1 [4994 B] 191s Get:27 http://ftpmaster.internal/ubuntu plucky/main arm64 libstdc++-14-dev arm64 14.2.0-9ubuntu1 [2473 kB] 191s Get:28 http://ftpmaster.internal/ubuntu plucky/main arm64 g++-14-aarch64-linux-gnu arm64 14.2.0-9ubuntu1 [12.1 MB] 191s Get:29 http://ftpmaster.internal/ubuntu plucky/main arm64 g++-14 arm64 14.2.0-9ubuntu1 [20.1 kB] 191s Get:30 http://ftpmaster.internal/ubuntu plucky/main arm64 g++-aarch64-linux-gnu arm64 4:14.1.0-2ubuntu1 [958 B] 191s Get:31 http://ftpmaster.internal/ubuntu plucky/main arm64 g++ arm64 4:14.1.0-2ubuntu1 [1080 B] 191s Get:32 http://ftpmaster.internal/ubuntu plucky/main arm64 build-essential arm64 12.10ubuntu1 [4932 B] 191s Get:33 http://ftpmaster.internal/ubuntu plucky/main arm64 libhttp-parser2.9 arm64 2.9.4-6build1 [21.9 kB] 191s Get:34 http://ftpmaster.internal/ubuntu plucky/main arm64 libgit2-1.7 arm64 1.7.2+ds-1ubuntu3 [528 kB] 191s Get:35 http://ftpmaster.internal/ubuntu plucky/main arm64 libstd-rust-1.80 arm64 1.80.1+dfsg0ubuntu1-0ubuntu1 [20.0 MB] 192s Get:36 http://ftpmaster.internal/ubuntu plucky/main arm64 libstd-rust-1.80-dev arm64 1.80.1+dfsg0ubuntu1-0ubuntu1 [40.8 MB] 195s Get:37 http://ftpmaster.internal/ubuntu plucky/main arm64 rustc-1.80 arm64 1.80.1+dfsg0ubuntu1-0ubuntu1 [3139 kB] 195s Get:38 http://ftpmaster.internal/ubuntu plucky/main arm64 cargo-1.80 arm64 1.80.1+dfsg0ubuntu1-0ubuntu1 [5764 kB] 195s Get:39 http://ftpmaster.internal/ubuntu plucky/main arm64 libjsoncpp25 arm64 1.9.5-6build1 [78.2 kB] 195s Get:40 http://ftpmaster.internal/ubuntu plucky/main arm64 librhash0 arm64 1.4.3-3build1 [126 kB] 195s Get:41 http://ftpmaster.internal/ubuntu plucky/main arm64 cmake-data all 3.30.3-1 [2246 kB] 196s Get:42 http://ftpmaster.internal/ubuntu plucky/main arm64 cmake arm64 3.30.3-1 [10.9 MB] 196s Get:43 http://ftpmaster.internal/ubuntu plucky/main arm64 libdebhelper-perl all 13.20ubuntu1 [94.2 kB] 196s Get:44 http://ftpmaster.internal/ubuntu plucky/main arm64 libtool all 2.4.7-8 [166 kB] 196s Get:45 http://ftpmaster.internal/ubuntu plucky/main arm64 dh-autoreconf all 20 [16.1 kB] 196s Get:46 http://ftpmaster.internal/ubuntu plucky/main arm64 libarchive-zip-perl all 1.68-1 [90.2 kB] 196s Get:47 http://ftpmaster.internal/ubuntu plucky/main arm64 libfile-stripnondeterminism-perl all 1.14.0-1 [20.1 kB] 196s Get:48 http://ftpmaster.internal/ubuntu plucky/main arm64 dh-strip-nondeterminism all 1.14.0-1 [5058 B] 196s Get:49 http://ftpmaster.internal/ubuntu plucky/main arm64 debugedit arm64 1:5.1-1 [45.9 kB] 196s Get:50 http://ftpmaster.internal/ubuntu plucky/main arm64 dwz arm64 0.15-1build6 [113 kB] 196s Get:51 http://ftpmaster.internal/ubuntu plucky/main arm64 gettext arm64 0.22.5-2 [930 kB] 197s Get:52 http://ftpmaster.internal/ubuntu plucky/main arm64 intltool-debian all 0.35.0+20060710.6 [23.2 kB] 197s Get:53 http://ftpmaster.internal/ubuntu plucky/main arm64 po-debconf all 1.0.21+nmu1 [233 kB] 197s Get:54 http://ftpmaster.internal/ubuntu plucky/main arm64 debhelper all 13.20ubuntu1 [893 kB] 197s Get:55 http://ftpmaster.internal/ubuntu plucky/universe arm64 dh-python all 6.20241024 [112 kB] 197s Get:56 http://ftpmaster.internal/ubuntu plucky/main arm64 fonts-dejavu-mono all 2.37-8 [502 kB] 197s Get:57 http://ftpmaster.internal/ubuntu plucky/main arm64 fonts-dejavu-core all 2.37-8 [835 kB] 197s Get:58 http://ftpmaster.internal/ubuntu plucky/main arm64 fontconfig-config arm64 2.15.0-1.1ubuntu2 [37.4 kB] 197s Get:59 http://ftpmaster.internal/ubuntu plucky/main arm64 libbrotli-dev arm64 1.1.0-2build3 [359 kB] 197s Get:60 http://ftpmaster.internal/ubuntu plucky/main arm64 libbz2-dev arm64 1.0.8-6 [36.1 kB] 197s Get:61 http://ftpmaster.internal/ubuntu plucky/main arm64 libexpat1-dev arm64 2.6.4-1 [129 kB] 197s Get:62 http://ftpmaster.internal/ubuntu plucky/main arm64 libfontconfig1 arm64 2.15.0-1.1ubuntu2 [142 kB] 197s Get:63 http://ftpmaster.internal/ubuntu plucky/main arm64 zlib1g-dev arm64 1:1.3.dfsg+really1.3.1-1ubuntu1 [894 kB] 197s Get:64 http://ftpmaster.internal/ubuntu plucky/main arm64 libpng-dev arm64 1.6.44-2 [270 kB] 197s Get:65 http://ftpmaster.internal/ubuntu plucky/main arm64 libfreetype-dev arm64 2.13.3+dfsg-1 [574 kB] 197s Get:66 http://ftpmaster.internal/ubuntu plucky/main arm64 uuid-dev arm64 2.40.2-1ubuntu1 [53.6 kB] 197s Get:67 http://ftpmaster.internal/ubuntu plucky/main arm64 libpkgconf3 arm64 1.8.1-4 [31.4 kB] 197s Get:68 http://ftpmaster.internal/ubuntu plucky/main arm64 pkgconf-bin arm64 1.8.1-4 [20.9 kB] 197s Get:69 http://ftpmaster.internal/ubuntu plucky/main arm64 pkgconf arm64 1.8.1-4 [16.7 kB] 197s Get:70 http://ftpmaster.internal/ubuntu plucky/main arm64 libfontconfig-dev arm64 2.15.0-1.1ubuntu2 [165 kB] 197s Get:71 http://ftpmaster.internal/ubuntu plucky/main arm64 libpython3.12-dev arm64 3.12.7-3 [5565 kB] 197s Get:72 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 libpython3-dev arm64 3.12.7-1 [10.3 kB] 197s Get:73 http://ftpmaster.internal/ubuntu plucky/main arm64 libpython3.13-stdlib arm64 3.13.0-2 [2073 kB] 197s Get:74 http://ftpmaster.internal/ubuntu plucky/main arm64 libpython3.13 arm64 3.13.0-2 [2262 kB] 198s Get:75 http://ftpmaster.internal/ubuntu plucky/main arm64 libpython3.13-dev arm64 3.13.0-2 [5386 kB] 198s Get:76 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 libpython3-all-dev arm64 3.12.7-1 [916 B] 198s Get:77 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ab-glyph-rasterizer-dev arm64 0.1.7-1 [12.2 kB] 198s Get:78 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-libm-dev arm64 0.2.8-1 [101 kB] 198s Get:79 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ab-glyph-rasterizer+libm-dev arm64 0.1.7-1 [1062 B] 198s Get:80 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-core-maths-dev arm64 0.1.0-2 [7944 B] 198s Get:81 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ttf-parser-dev arm64 0.24.1-1 [148 kB] 198s Get:82 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-owned-ttf-parser-dev arm64 0.24.0-1 [129 kB] 198s Get:83 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ab-glyph-dev arm64 0.2.28-1 [20.7 kB] 198s Get:84 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cfg-if-dev arm64 1.0.0-1 [10.5 kB] 198s Get:85 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cpp-demangle-dev arm64 0.4.0-1 [66.1 kB] 198s Get:86 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-fallible-iterator-dev arm64 0.3.0-2 [20.3 kB] 198s Get:87 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicode-ident-dev arm64 1.0.13-1 [38.5 kB] 198s Get:88 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-proc-macro2-dev arm64 1.0.86-1 [44.8 kB] 198s Get:89 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-quote-dev arm64 1.0.37-1 [29.5 kB] 198s Get:90 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-syn-dev arm64 2.0.85-1 [219 kB] 198s Get:91 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-derive-arbitrary-dev arm64 1.3.2-1 [12.3 kB] 198s Get:92 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-arbitrary-dev arm64 1.3.2-1 [31.4 kB] 198s Get:93 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-equivalent-dev arm64 1.0.1-1 [8240 B] 198s Get:94 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-critical-section-dev arm64 1.1.3-1 [20.5 kB] 198s Get:95 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-serde-derive-dev arm64 1.0.210-1 [50.1 kB] 198s Get:96 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-serde-dev arm64 1.0.210-2 [66.4 kB] 198s Get:97 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-portable-atomic-dev arm64 1.9.0-4 [124 kB] 198s Get:98 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rustc-std-workspace-core-dev arm64 1.0.0-1 [3020 B] 198s Get:99 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-libc-dev arm64 0.2.161-1 [379 kB] 198s Get:100 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-getrandom-dev arm64 0.2.12-1 [36.4 kB] 198s Get:101 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-smallvec-dev arm64 1.13.2-1 [35.5 kB] 198s Get:102 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-parking-lot-core-dev arm64 0.9.10-1 [32.6 kB] 198s Get:103 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-once-cell-dev arm64 1.20.2-1 [31.9 kB] 198s Get:104 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crunchy-dev arm64 0.2.2-1 [5336 B] 198s Get:105 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tiny-keccak-dev arm64 2.0.2-1 [20.9 kB] 198s Get:106 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-const-random-macro-dev arm64 0.1.16-2 [10.5 kB] 198s Get:107 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-const-random-dev arm64 0.1.17-2 [8588 B] 198s Get:108 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-version-check-dev arm64 0.9.5-1 [16.9 kB] 198s Get:109 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-byteorder-dev arm64 1.5.0-1 [22.4 kB] 198s Get:110 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-zerocopy-derive-dev arm64 0.7.32-2 [29.7 kB] 198s Get:111 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-zerocopy-dev arm64 0.7.32-1 [116 kB] 198s Get:112 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ahash-dev all 0.8.11-8 [37.9 kB] 198s Get:113 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-allocator-api2-dev arm64 0.2.16-1 [54.8 kB] 199s Get:114 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-compiler-builtins-dev arm64 0.1.101-1 [156 kB] 199s Get:115 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-either-dev arm64 1.13.0-1 [20.2 kB] 199s Get:116 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crossbeam-utils-dev arm64 0.8.19-1 [41.1 kB] 199s Get:117 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crossbeam-epoch-dev arm64 0.9.18-1 [42.3 kB] 199s Get:118 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crossbeam-epoch+std-dev arm64 0.9.18-1 [1128 B] 199s Get:119 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crossbeam-deque-dev arm64 0.8.5-1 [22.4 kB] 199s Get:120 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rayon-core-dev arm64 1.12.1-1 [63.7 kB] 199s Get:121 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rayon-dev arm64 1.10.0-1 [149 kB] 199s Get:122 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-hashbrown-dev arm64 0.14.5-5 [110 kB] 199s Get:123 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-indexmap-dev arm64 2.2.6-1 [66.7 kB] 199s Get:124 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-stable-deref-trait-dev arm64 1.2.0-1 [9794 B] 199s Get:125 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-gimli-dev arm64 0.28.1-2 [209 kB] 199s Get:126 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-memmap2-dev arm64 0.9.3-1 [30.8 kB] 199s Get:127 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crc32fast-dev arm64 1.4.2-1 [39.8 kB] 199s Get:128 http://ftpmaster.internal/ubuntu plucky/main arm64 pkg-config arm64 1.8.1-4 [7362 B] 199s Get:129 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pkg-config-dev arm64 0.3.27-1 [21.5 kB] 199s Get:130 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-libz-sys-dev arm64 1.1.20-1 [19.8 kB] 199s Get:131 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-adler-dev arm64 1.0.2-2 [15.3 kB] 199s Get:132 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-miniz-oxide-dev arm64 0.7.1-1 [51.5 kB] 199s Get:133 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-flate2-dev arm64 1.0.34-1 [94.5 kB] 199s Get:134 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-derive-dev arm64 2.6.1-2 [11.0 kB] 199s Get:135 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-dev arm64 2.6.1-2 [28.0 kB] 199s Get:136 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-ref-dev arm64 2.6.1-1 [8942 B] 199s Get:137 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-erased-serde-dev arm64 0.3.31-1 [22.7 kB] 199s Get:138 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-serde-fmt-dev all 1.0.3-3 [6956 B] 199s Get:139 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-syn-1-dev arm64 1.0.109-3 [188 kB] 199s Get:140 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-no-panic-dev arm64 0.1.13-1 [11.3 kB] 199s Get:141 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-itoa-dev arm64 1.0.9-1 [13.1 kB] 199s Get:142 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ryu-dev arm64 1.0.15-1 [41.7 kB] 199s Get:143 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-serde-json-dev arm64 1.0.128-1 [128 kB] 199s Get:144 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-serde-test-dev arm64 1.0.171-1 [20.6 kB] 199s Get:145 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-value-bag-serde1-dev arm64 1.9.0-1 [7820 B] 199s Get:146 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-buffer-dev arm64 2.6.1-1 [16.7 kB] 199s Get:147 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-dynamic-dev arm64 2.6.1-1 [9540 B] 199s Get:148 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-fmt-dev arm64 2.6.1-1 [12.0 kB] 199s Get:149 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sval-serde-dev arm64 2.6.1-1 [13.2 kB] 199s Get:150 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-value-bag-sval2-dev arm64 1.9.0-1 [7860 B] 199s Get:151 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-value-bag-dev arm64 1.9.0-1 [37.6 kB] 199s Get:152 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-log-dev arm64 0.4.22-1 [43.0 kB] 199s Get:153 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-memchr-dev arm64 2.7.4-1 [71.8 kB] 199s Get:154 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ppv-lite86-dev arm64 0.2.16-1 [21.9 kB] 199s Get:155 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-core-dev arm64 0.6.4-2 [23.8 kB] 199s Get:156 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-chacha-dev arm64 0.3.1-2 [16.9 kB] 199s Get:157 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-core+getrandom-dev arm64 0.6.4-2 [1052 B] 199s Get:158 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-core+serde-dev arm64 0.6.4-2 [1108 B] 199s Get:159 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-core+std-dev arm64 0.6.4-2 [1050 B] 199s Get:160 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-dev arm64 0.8.5-1 [77.5 kB] 199s Get:161 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicode-segmentation-dev arm64 1.11.0-1 [74.2 kB] 199s Get:162 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-convert-case-dev arm64 0.6.0-2 [19.5 kB] 199s Get:163 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-semver-dev arm64 1.0.23-1 [30.6 kB] 199s Get:164 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rustc-version-dev arm64 0.4.0-1 [13.8 kB] 199s Get:165 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-derive-more-0.99-dev arm64 0.99.18-2 [49.9 kB] 199s Get:166 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cfg-if-0.1-dev arm64 0.1.10-3 [10.5 kB] 199s Get:167 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-blobby-dev arm64 0.3.1-1 [11.3 kB] 199s Get:168 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-typenum-dev arm64 1.17.0-2 [41.2 kB] 199s Get:169 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-zeroize-derive-dev arm64 1.4.2-1 [12.7 kB] 199s Get:170 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-zeroize-dev arm64 1.8.1-1 [21.6 kB] 199s Get:171 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-generic-array-dev arm64 0.14.7-1 [16.9 kB] 199s Get:172 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-block-buffer-dev arm64 0.10.2-2 [12.2 kB] 199s Get:173 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-const-oid-dev arm64 0.9.3-1 [40.9 kB] 199s Get:174 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-crypto-common-dev arm64 0.1.6-1 [10.5 kB] 199s Get:175 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-subtle-dev arm64 2.6.1-1 [16.1 kB] 199s Get:176 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-digest-dev arm64 0.10.7-2 [20.9 kB] 199s Get:177 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-static-assertions-dev arm64 1.1.0-1 [19.0 kB] 199s Get:178 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-twox-hash-dev arm64 1.6.3-1 [21.6 kB] 199s Get:179 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ruzstd-dev arm64 0.5.0-1 [44.6 kB] 199s Get:180 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-object-dev arm64 0.32.2-1 [228 kB] 200s Get:181 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rustc-demangle-dev arm64 0.1.21-1 [27.7 kB] 200s Get:182 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-addr2line-dev arm64 0.21.0-2 [36.4 kB] 200s Get:183 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-aho-corasick-dev arm64 1.1.3-1 [146 kB] 200s Get:184 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bitflags-1-dev arm64 1.3.2-5 [25.3 kB] 200s Get:185 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anes-dev arm64 0.1.6-1 [21.1 kB] 200s Get:186 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anstyle-dev arm64 1.0.8-1 [16.7 kB] 200s Get:187 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-arrayvec-dev arm64 0.7.4-2 [29.9 kB] 200s Get:188 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-utf8parse-dev arm64 0.2.1-1 [15.0 kB] 200s Get:189 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anstyle-parse-dev arm64 0.2.1-1 [17.1 kB] 200s Get:190 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anstyle-query-dev arm64 1.0.0-1 [9768 B] 200s Get:191 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-colorchoice-dev arm64 1.0.0-1 [8336 B] 200s Get:192 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anstream-dev arm64 0.6.15-1 [25.7 kB] 200s Get:193 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-jobserver-dev arm64 0.1.32-1 [29.1 kB] 200s Get:194 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-shlex-dev arm64 1.3.0-1 [20.1 kB] 200s Get:195 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cc-dev arm64 1.1.14-1 [73.6 kB] 200s Get:196 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-backtrace-dev arm64 0.3.69-2 [69.9 kB] 200s Get:197 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-anyhow-dev arm64 1.0.86-1 [44.3 kB] 200s Get:198 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bytecheck-derive-dev arm64 0.6.12-1 [7086 B] 200s Get:199 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ptr-meta-derive-dev arm64 0.1.4-1 [3964 B] 200s Get:200 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ptr-meta-dev arm64 0.1.4-1 [7342 B] 200s Get:201 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-simdutf8-dev arm64 0.1.4-4 [27.2 kB] 200s Get:202 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bytemuck-derive-dev arm64 1.5.0-2 [18.7 kB] 200s Get:203 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bytemuck-dev arm64 1.14.0-1 [42.7 kB] 200s Get:204 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-atomic-dev arm64 0.6.0-1 [15.5 kB] 200s Get:205 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-md5-asm-dev arm64 0.5.0-2 [7512 B] 200s Get:206 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-md-5-dev arm64 0.10.6-1 [17.5 kB] 200s Get:207 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cpufeatures-dev arm64 0.2.11-1 [14.9 kB] 200s Get:208 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sha1-asm-dev arm64 0.5.1-2 [8058 B] 200s Get:209 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sha1-dev arm64 0.10.6-1 [16.0 kB] 200s Get:210 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-slog-dev arm64 2.7.0-1 [44.0 kB] 200s Get:211 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-uuid-dev arm64 1.10.0-1 [44.2 kB] 200s Get:212 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bytecheck-dev arm64 0.6.12-1 [10.2 kB] 200s Get:213 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-autocfg-dev arm64 1.1.0-1 [15.1 kB] 200s Get:214 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-traits-dev arm64 0.2.19-2 [46.2 kB] 200s Get:215 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-funty-dev arm64 2.0.0-1 [13.8 kB] 200s Get:216 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-radium-dev arm64 1.1.0-1 [14.9 kB] 200s Get:217 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tap-dev arm64 1.0.1-1 [12.7 kB] 200s Get:218 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-traitobject-dev arm64 0.1.0-1 [4540 B] 200s Get:219 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unsafe-any-dev arm64 0.4.2-2 [4622 B] 200s Get:220 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-typemap-dev arm64 0.3.3-2 [6724 B] 200s Get:221 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wyz-dev arm64 0.5.1-1 [19.7 kB] 200s Get:222 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bitvec-dev arm64 1.0.1-1 [179 kB] 200s Get:223 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bytes-dev arm64 1.8.0-1 [56.9 kB] 200s Get:224 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rend-dev arm64 0.4.0-1 [10.3 kB] 200s Get:225 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rkyv-derive-dev arm64 0.7.44-1 [17.5 kB] 200s Get:226 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-seahash-dev arm64 4.1.0-1 [25.1 kB] 200s Get:227 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-smol-str-dev arm64 0.2.0-1 [15.2 kB] 200s Get:228 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tinyvec-dev arm64 1.6.0-2 [37.7 kB] 200s Get:229 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tinyvec-macros-dev arm64 0.1.0-1 [3852 B] 200s Get:230 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tinyvec+tinyvec-macros-dev arm64 1.6.0-2 [1124 B] 200s Get:231 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rkyv-dev arm64 0.7.44-1 [94.4 kB] 201s Get:232 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-complex-dev arm64 0.4.6-2 [30.8 kB] 201s Get:233 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-approx-dev arm64 0.5.1-1 [16.0 kB] 201s Get:234 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-array-init-dev arm64 2.0.1-1 [12.3 kB] 201s Get:235 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-attributes-dev all 1.1.2-6 [6756 B] 201s Get:236 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-concurrent-queue-dev arm64 2.5.0-4 [23.9 kB] 201s Get:237 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-parking-dev arm64 2.2.0-1 [11.6 kB] 201s Get:238 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pin-project-lite-dev arm64 0.2.13-1 [30.2 kB] 201s Get:239 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-event-listener-dev all 5.3.1-8 [29.6 kB] 201s Get:240 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-event-listener-strategy-dev arm64 0.5.2-3 [12.6 kB] 201s Get:241 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-core-dev arm64 0.3.30-1 [16.7 kB] 201s Get:242 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-channel-dev all 2.3.1-8 [13.1 kB] 201s Get:243 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-task-dev all 4.7.1-3 [29.4 kB] 201s Get:244 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-fastrand-dev arm64 2.1.1-1 [17.8 kB] 201s Get:245 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-io-dev arm64 0.3.31-1 [11.2 kB] 201s Get:246 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-lite-dev arm64 2.3.0-2 [38.6 kB] 201s Get:247 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-slab-dev arm64 0.4.9-1 [21.2 kB] 201s Get:248 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-executor-dev all 1.13.1-1 [18.7 kB] 201s Get:249 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-lock-dev all 3.4.0-4 [29.3 kB] 201s Get:250 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-atomic-waker-dev arm64 1.1.2-1 [14.3 kB] 201s Get:251 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tracing-attributes-dev arm64 0.1.27-1 [33.3 kB] 201s Get:252 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-valuable-derive-dev arm64 0.1.0-1 [5942 B] 201s Get:253 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-valuable-dev arm64 0.1.0-4 [23.5 kB] 201s Get:254 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tracing-core-dev arm64 0.1.32-1 [53.8 kB] 201s Get:255 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tracing-dev arm64 0.1.40-1 [69.5 kB] 201s Get:256 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-blocking-dev all 1.6.1-5 [17.5 kB] 201s Get:257 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-fs-dev all 2.1.2-4 [15.3 kB] 201s Get:258 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bitflags-dev arm64 2.6.0-1 [41.1 kB] 201s Get:259 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-compiler-builtins+core-dev arm64 0.1.101-1 [1090 B] 201s Get:260 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-compiler-builtins+rustc-dep-of-std-dev arm64 0.1.101-1 [1104 B] 201s Get:261 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-errno-dev arm64 0.3.8-1 [13.0 kB] 201s Get:262 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-linux-raw-sys-dev arm64 0.4.14-1 [138 kB] 201s Get:263 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rustix-dev arm64 0.38.37-1 [272 kB] 201s Get:264 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-polling-dev arm64 3.4.0-1 [47.8 kB] 201s Get:265 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-io-dev arm64 2.3.3-4 [41.0 kB] 201s Get:266 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-mio-dev arm64 1.0.2-2 [87.6 kB] 201s Get:267 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-owning-ref-dev arm64 0.4.1-1 [13.7 kB] 201s Get:268 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-scopeguard-dev arm64 1.2.0-1 [13.3 kB] 201s Get:269 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-lock-api-dev arm64 0.4.12-1 [22.9 kB] 201s Get:270 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-parking-lot-dev arm64 0.12.3-1 [38.7 kB] 201s Get:271 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-signal-hook-registry-dev arm64 1.4.0-1 [19.2 kB] 201s Get:272 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-socket2-dev arm64 0.5.7-1 [48.3 kB] 201s Get:273 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tokio-macros-dev arm64 2.4.0-2 [14.0 kB] 201s Get:274 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tokio-dev arm64 1.39.3-3 [561 kB] 201s Get:275 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-global-executor-dev arm64 2.4.1-5 [14.6 kB] 201s Get:276 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-net-dev all 2.0.0-4 [14.6 kB] 201s Get:277 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-signal-dev arm64 0.2.10-1 [16.0 kB] 201s Get:278 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-process-dev all 2.3.0-1 [21.2 kB] 201s Get:279 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-kv-log-macro-dev all 1.0.8-4 [7290 B] 201s Get:280 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pin-utils-dev arm64 0.1.0-1 [9340 B] 201s Get:281 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-async-std-dev all 1.13.0-1 [170 kB] 201s Get:282 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-base64-dev arm64 0.21.7-1 [65.1 kB] 201s Get:283 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bit-vec-dev arm64 0.6.3-1 [21.1 kB] 201s Get:284 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bit-set-dev arm64 0.5.2-1 [15.7 kB] 201s Get:285 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bit-set+std-dev arm64 0.5.2-1 [1084 B] 201s Get:286 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-regex-syntax-dev arm64 0.8.5-1 [203 kB] 201s Get:287 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-regex-automata-dev arm64 0.4.9-1 [425 kB] 201s Get:288 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bstr-dev arm64 1.7.0-2build1 [271 kB] 201s Get:289 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-bumpalo-dev arm64 3.16.0-1 [75.7 kB] 201s Get:290 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cast-dev arm64 0.3.0-1 [13.1 kB] 201s Get:291 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-iana-time-zone-dev arm64 0.1.60-1 [25.1 kB] 201s Get:292 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-shared-dev arm64 0.2.87-1 [9090 B] 201s Get:293 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-backend-dev arm64 0.2.87-1 [27.0 kB] 201s Get:294 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-macro-support-dev arm64 0.2.87-1 [21.2 kB] 201s Get:295 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-macro-dev arm64 0.2.87-1 [16.6 kB] 201s Get:296 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-dev arm64 0.2.87-1 [157 kB] 201s Get:297 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-macro-support+spans-dev arm64 0.2.87-1 [1074 B] 201s Get:298 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen-macro+spans-dev arm64 0.2.87-1 [1058 B] 201s Get:299 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen+spans-dev arm64 0.2.87-1 [1038 B] 201s Get:300 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wasm-bindgen+default-dev arm64 0.2.87-1 [1046 B] 201s Get:301 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-js-sys-dev arm64 0.3.64-1 [71.9 kB] 202s Get:302 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pure-rust-locales-dev arm64 0.8.1-1 [112 kB] 202s Get:303 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-chrono-dev arm64 0.4.38-2 [172 kB] 202s Get:304 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-regex-dev arm64 1.10.6-1 [199 kB] 202s Get:305 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-parse-zoneinfo-dev arm64 0.3.0-1 [71.0 kB] 202s Get:306 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-siphasher-dev arm64 0.3.10-1 [12.0 kB] 202s Get:307 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf-shared-dev arm64 0.11.2-1 [15.6 kB] 202s Get:308 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf-dev arm64 0.11.2-1 [21.6 kB] 202s Get:309 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-uncased-dev arm64 0.9.6-2 [12.2 kB] 202s Get:310 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf-shared+uncased-dev arm64 0.11.2-1 [1028 B] 202s Get:311 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf+uncased-dev arm64 0.11.2-1 [1028 B] 202s Get:312 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ciborium-io-dev arm64 0.2.2-1 [8180 B] 202s Get:313 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-half-dev arm64 1.8.2-4 [34.8 kB] 202s Get:314 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ciborium-ll-dev arm64 0.2.2-1 [15.8 kB] 202s Get:315 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ciborium-dev arm64 0.2.2-2 [32.6 kB] 202s Get:316 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-clap-lex-dev arm64 0.7.2-2 [14.3 kB] 202s Get:317 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-strsim-dev arm64 0.11.1-1 [15.9 kB] 202s Get:318 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-terminal-size-dev arm64 0.3.0-2 [12.6 kB] 202s Get:319 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicase-dev arm64 2.7.0-1 [19.4 kB] 202s Get:320 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicode-width-dev arm64 0.1.14-1 [196 kB] 202s Get:321 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-clap-builder-dev arm64 4.5.15-2 [135 kB] 202s Get:322 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-heck-dev arm64 0.4.1-1 [13.3 kB] 202s Get:323 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-clap-derive-dev arm64 4.5.13-2 [29.3 kB] 202s Get:324 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-clap-dev arm64 4.5.16-1 [52.3 kB] 202s Get:325 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-csv-core-dev arm64 0.1.11-1 [25.9 kB] 202s Get:326 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-csv-dev arm64 1.3.0-1 [729 kB] 202s Get:327 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-sink-dev arm64 0.3.31-1 [10.1 kB] 202s Get:328 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-channel-dev arm64 0.3.30-1 [31.8 kB] 202s Get:329 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-task-dev arm64 0.3.30-1 [13.5 kB] 202s Get:330 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-macro-dev arm64 0.3.30-1 [13.3 kB] 202s Get:331 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-util-dev arm64 0.3.30-2 [127 kB] 202s Get:332 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-cpus-dev arm64 1.16.0-1 [18.1 kB] 202s Get:333 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-executor-dev arm64 0.3.30-1 [19.8 kB] 202s Get:334 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-futures-dev arm64 0.3.30-2 [53.2 kB] 202s Get:335 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-is-terminal-dev arm64 0.4.13-1 [8264 B] 202s Get:336 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-itertools-dev arm64 0.10.5-1 [101 kB] 202s Get:337 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-oorandom-dev arm64 11.1.3-1 [11.3 kB] 202s Get:338 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-winapi-i686-pc-windows-gnu-dev arm64 0.4.0-1 [3652 B] 202s Get:339 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-winapi-x86-64-pc-windows-gnu-dev arm64 0.4.0-1 [3660 B] 202s Get:340 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-winapi-dev arm64 0.3.9-1 [953 kB] 202s Get:341 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-dirs-sys-next-dev arm64 0.1.1-1 [12.1 kB] 202s Get:342 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-dirs-next-dev arm64 2.0.0-1 [13.1 kB] 202s Get:343 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-float-ord-dev arm64 0.3.2-1 [9400 B] 202s Get:344 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-cmake-dev arm64 0.1.45-1 [16.0 kB] 202s Get:345 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-freetype-sys-dev arm64 0.13.1-1 [11.8 kB] 202s Get:346 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-freetype-dev arm64 0.7.0-4 [20.4 kB] 202s Get:347 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-spin-dev arm64 0.9.8-4 [33.4 kB] 202s Get:348 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-lazy-static-dev arm64 1.5.0-1 [14.2 kB] 202s Get:349 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pathfinder-simd-dev arm64 0.5.2-1 [20.1 kB] 202s Get:350 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pathfinder-geometry-dev arm64 0.5.1-1 [13.2 kB] 202s Get:351 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-winapi-util-dev arm64 0.1.6-1 [14.0 kB] 202s Get:352 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-same-file-dev arm64 1.0.6-1 [11.5 kB] 202s Get:353 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-walkdir-dev arm64 2.5.0-1 [24.5 kB] 203s Get:354 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-const-cstr-dev arm64 0.3.0-1 [9068 B] 203s Get:355 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-libloading-dev arm64 0.8.5-1 [29.2 kB] 203s Get:356 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-dlib-dev arm64 0.5.2-2 [7970 B] 203s Get:357 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-yeslogic-fontconfig-sys-dev arm64 3.0.1-1 [8110 B] 203s Get:358 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-font-kit-dev arm64 0.11.0-2 [56.2 kB] 203s Get:359 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-color-quant-dev arm64 1.1.0-1 [8462 B] 203s Get:360 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-weezl-dev arm64 0.1.5-1 [30.3 kB] 203s Get:361 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-gif-dev arm64 0.11.3-1 [31.9 kB] 203s Get:362 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-jpeg-decoder-dev arm64 0.3.0-1 [717 kB] 203s Get:363 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-integer-dev arm64 0.1.46-1 [22.6 kB] 203s Get:364 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-humantime-dev arm64 2.1.0-1 [18.2 kB] 203s Get:365 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-termcolor-dev arm64 1.4.1-1 [19.7 kB] 203s Get:366 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-env-logger-dev arm64 0.10.2-2 [34.4 kB] 203s Get:367 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-quickcheck-dev arm64 1.0.3-3 [27.9 kB] 203s Get:368 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-bigint-dev arm64 0.4.6-1 [84.9 kB] 203s Get:369 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-rational-dev arm64 0.4.2-1 [28.7 kB] 203s Get:370 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-png-dev arm64 0.17.7-3 [63.4 kB] 203s Get:371 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-qoi-dev arm64 0.4.1-2 [56.7 kB] 203s Get:372 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tiff-dev arm64 0.9.0-1 [1413 kB] 203s Get:373 http://ftpmaster.internal/ubuntu plucky/main arm64 libsharpyuv0 arm64 1.4.0-0.1 [16.3 kB] 203s Get:374 http://ftpmaster.internal/ubuntu plucky/main arm64 libwebp7 arm64 1.4.0-0.1 [192 kB] 203s Get:375 http://ftpmaster.internal/ubuntu plucky/main arm64 libwebpdemux2 arm64 1.4.0-0.1 [12.3 kB] 203s Get:376 http://ftpmaster.internal/ubuntu plucky/main arm64 libwebpmux3 arm64 1.4.0-0.1 [25.1 kB] 203s Get:377 http://ftpmaster.internal/ubuntu plucky/main arm64 libwebpdecoder3 arm64 1.4.0-0.1 [89.0 kB] 203s Get:378 http://ftpmaster.internal/ubuntu plucky/main arm64 libsharpyuv-dev arm64 1.4.0-0.1 [17.9 kB] 203s Get:379 http://ftpmaster.internal/ubuntu plucky/main arm64 libwebp-dev arm64 1.4.0-0.1 [339 kB] 203s Get:380 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-libwebp-sys-dev arm64 0.9.5-1build1 [1357 kB] 203s Get:381 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-webp-dev arm64 0.2.6-1 [1846 kB] 203s Get:382 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-image-dev arm64 0.24.7-2 [229 kB] 203s Get:383 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-plotters-backend-dev arm64 0.3.7-1 [15.7 kB] 203s Get:384 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-plotters-bitmap-dev arm64 0.3.3-3 [17.1 kB] 203s Get:385 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-plotters-svg-dev arm64 0.3.5-1 [9258 B] 203s Get:386 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-web-sys-dev arm64 0.3.64-2 [581 kB] 203s Get:387 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-plotters-dev arm64 0.3.5-4 [118 kB] 203s Get:388 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-smol-dev all 2.0.2-1 [205 kB] 203s Get:389 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tinytemplate-dev arm64 1.2.1-1 [26.8 kB] 203s Get:390 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-criterion-dev all 0.5.1-6 [104 kB] 203s Get:391 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf-generator-dev arm64 0.11.2-2 [12.3 kB] 203s Get:392 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-phf-codegen-dev arm64 0.11.2-1 [14.3 kB] 203s Get:393 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-chrono-tz-build-dev arm64 0.2.1-1 [12.1 kB] 203s Get:394 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-chrono-tz-dev arm64 0.8.6-2 [513 kB] 203s Get:395 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ctor-dev arm64 0.1.26-1 [12.0 kB] 203s Get:396 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-powerfmt-macros-dev arm64 0.1.0-1 [10.5 kB] 203s Get:397 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-powerfmt-dev arm64 0.2.0-1 [16.5 kB] 203s Get:398 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-deranged-dev arm64 0.3.11-1 [18.4 kB] 203s Get:399 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-eui48-dev arm64 1.1.0-2 [16.1 kB] 203s Get:400 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-indenter-dev arm64 0.3.3-1 [8646 B] 204s Get:401 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-eyre-dev arm64 0.6.12-1 [38.0 kB] 204s Get:402 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-eyre+default-dev arm64 0.6.12-1 [1050 B] 204s Get:403 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-fancy-regex-dev arm64 0.11.0-2 [54.7 kB] 204s Get:404 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-fnv-dev arm64 1.0.7-1 [12.8 kB] 204s Get:405 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-geo-types-dev arm64 0.7.11-2 [32.8 kB] 204s Get:406 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-ghost-dev arm64 0.1.5-1 [16.1 kB] 204s Get:407 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-hmac-dev arm64 0.12.1-1 [43.9 kB] 204s Get:408 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-indoc-dev arm64 2.0.5-1 [16.7 kB] 204s Get:409 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-inventory-dev arm64 0.3.2-1 [13.5 kB] 204s Get:410 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-memoffset-dev arm64 0.8.0-1 [10.9 kB] 204s Get:411 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-conv-dev arm64 0.1.0-1 [8990 B] 204s Get:412 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-num-threads-dev arm64 0.1.7-1 [9150 B] 204s Get:413 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-postgres-derive-dev arm64 0.4.5-1 [13.4 kB] 204s Get:414 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sha2-asm-dev arm64 0.6.2-2 [14.4 kB] 204s Get:415 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-sha2-dev arm64 0.10.8-1 [25.6 kB] 204s Get:416 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicode-bidi-dev arm64 0.3.13-1 [39.8 kB] 204s Get:417 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unicode-normalization-dev arm64 0.1.22-1 [104 kB] 204s Get:418 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-stringprep-dev arm64 0.1.2-1 [16.5 kB] 204s Get:419 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-postgres-protocol-dev arm64 0.6.6-2 [25.9 kB] 204s Get:420 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-time-core-dev arm64 0.1.2-1 [9134 B] 204s Get:421 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-time-macros-dev arm64 0.2.16-1 [25.1 kB] 204s Get:422 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-time-dev arm64 0.3.36-2 [99.4 kB] 204s Get:423 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-postgres-types-dev arm64 0.2.6-2 [30.1 kB] 204s Get:424 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rand-xorshift-dev arm64 0.3.0-2 [10.9 kB] 204s Get:425 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-quick-error-dev arm64 2.0.1-1 [15.6 kB] 204s Get:426 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-tempfile-dev arm64 3.13.0-1 [35.0 kB] 204s Get:427 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rusty-fork-dev arm64 0.3.0-1 [20.4 kB] 204s Get:428 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-wait-timeout-dev arm64 0.2.0-1 [14.2 kB] 204s Get:429 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rusty-fork+wait-timeout-dev arm64 0.3.0-1 [1132 B] 204s Get:430 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unarray-dev arm64 0.1.4-1 [14.6 kB] 204s Get:431 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-proptest-dev arm64 1.5.0-2 [171 kB] 204s Get:432 http://ftpmaster.internal/ubuntu plucky/universe arm64 llvm-19-runtime arm64 1:19.1.2-1ubuntu1 [532 kB] 204s Get:433 http://ftpmaster.internal/ubuntu plucky/universe arm64 llvm-runtime arm64 1:19.0-60~exp1 [5608 B] 204s Get:434 http://ftpmaster.internal/ubuntu plucky/universe arm64 llvm-19-linker-tools arm64 1:19.1.2-1ubuntu1 [1232 kB] 204s Get:435 http://ftpmaster.internal/ubuntu plucky/universe arm64 libpfm4 arm64 4.13.0+git83-g91970fe-1 [71.9 kB] 204s Get:436 http://ftpmaster.internal/ubuntu plucky/universe arm64 llvm-19 arm64 1:19.1.2-1ubuntu1 [17.0 MB] 206s Get:437 http://ftpmaster.internal/ubuntu plucky/universe arm64 llvm arm64 1:19.0-60~exp1 [4140 B] 206s Get:438 http://ftpmaster.internal/ubuntu plucky/universe arm64 binutils-mingw-w64-x86-64 arm64 2.43.1-4ubuntu1+12 [3460 kB] 206s Get:439 http://ftpmaster.internal/ubuntu plucky/universe arm64 binutils-mingw-w64-i686 arm64 2.43.1-4ubuntu1+12 [3166 kB] 206s Get:440 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-python3-dll-a-dev arm64 0.2.10-1 [31.6 kB] 206s Get:441 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-target-lexicon-dev arm64 0.12.14-1 [25.1 kB] 206s Get:442 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pyo3-build-config-dev arm64 0.22.6-1 [30.8 kB] 206s Get:443 http://ftpmaster.internal/ubuntu plucky/main arm64 python3.12-dev arm64 3.12.7-3 [505 kB] 206s Get:444 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pyo3-ffi-dev arm64 0.22.6-1build1 [62.6 kB] 206s Get:445 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pyo3-macros-backend-dev arm64 0.22.6-1 [58.5 kB] 206s Get:446 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pyo3-macros-dev arm64 0.22.6-1 [10.4 kB] 206s Get:447 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rust-decimal-dev arm64 1.36.0-1 [114 kB] 206s Get:448 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-unindent-dev arm64 0.2.3-1 [9188 B] 206s Get:449 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-pyo3-dev arm64 0.22.6-1 [415 kB] 206s Get:450 http://ftpmaster.internal/ubuntu plucky/universe arm64 librust-rustc-hash-dev arm64 1.1.0-1 [10.8 kB] 206s Get:451 http://ftpmaster.internal/ubuntu plucky/universe arm64 pybuild-plugin-autopkgtest all 6.20241024 [1746 B] 206s Get:452 http://ftpmaster.internal/ubuntu plucky/main arm64 python3-packaging all 24.2-1 [51.5 kB] 206s Get:453 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-pyproject-hooks all 1.2.0-1 [10.2 kB] 206s Get:454 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-toml all 0.10.2-1 [16.5 kB] 206s Get:455 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-wheel all 0.45.1-1 [57.7 kB] 206s Get:456 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-build all 1.2.2-1 [31.0 kB] 206s Get:457 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-installer all 0.7.0+dfsg1-3 [17.4 kB] 206s Get:458 http://ftpmaster.internal/ubuntu plucky/universe arm64 pybuild-plugin-pyproject all 6.20241024 [1728 B] 206s Get:459 http://ftpmaster.internal/ubuntu plucky/main arm64 python3.13 arm64 3.13.0-2 [719 kB] 206s Get:460 http://ftpmaster.internal/ubuntu plucky-proposed/main arm64 python3-all arm64 3.12.7-1 [890 B] 206s Get:461 http://ftpmaster.internal/ubuntu plucky/main arm64 python3-dateutil all 2.9.0-3 [80.2 kB] 206s Get:462 http://ftpmaster.internal/ubuntu plucky/main arm64 python3-sortedcontainers all 2.4.0-2 [27.6 kB] 206s Get:463 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-hypothesis all 6.119.3-1 [329 kB] 206s Get:464 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-iniconfig all 1.1.1-2 [6024 B] 206s Get:465 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-pluggy all 1.5.0-1 [21.0 kB] 206s Get:466 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-pytest all 8.3.3-1 [251 kB] 206s Get:467 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-regex arm64 0.1.20240724-1build1 [285 kB] 206s Get:468 http://ftpmaster.internal/ubuntu plucky/main arm64 python3-semantic-version all 2.10.0-2 [15.1 kB] 206s Get:469 http://ftpmaster.internal/ubuntu plucky/main arm64 rustc arm64 1.80.1ubuntu2 [2754 B] 206s Get:470 http://ftpmaster.internal/ubuntu plucky/main arm64 cargo arm64 1.80.1ubuntu2 [2244 B] 206s Get:471 http://ftpmaster.internal/ubuntu plucky/universe arm64 python3-setuptools-rust all 1.9.0+dfsg-2 [23.1 kB] 206s Get:472 http://ftpmaster.internal/ubuntu plucky-proposed/universe arm64 python3-tiktoken arm64 0.8.0-1build1 [753 kB] 207s Fetched 223 MB in 19s (11.8 MB/s) 207s Selecting previously unselected package libpython3.13-minimal:arm64. 208s (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 ... 80333 files and directories currently installed.) 208s Preparing to unpack .../000-libpython3.13-minimal_3.13.0-2_arm64.deb ... 208s Unpacking libpython3.13-minimal:arm64 (3.13.0-2) ... 208s Selecting previously unselected package python3.13-minimal. 208s Preparing to unpack .../001-python3.13-minimal_3.13.0-2_arm64.deb ... 208s Unpacking python3.13-minimal (3.13.0-2) ... 208s Selecting previously unselected package m4. 208s Preparing to unpack .../002-m4_1.4.19-4build1_arm64.deb ... 208s Unpacking m4 (1.4.19-4build1) ... 208s Selecting previously unselected package autoconf. 208s Preparing to unpack .../003-autoconf_2.72-3_all.deb ... 208s Unpacking autoconf (2.72-3) ... 208s Selecting previously unselected package autotools-dev. 208s Preparing to unpack .../004-autotools-dev_20220109.1_all.deb ... 208s Unpacking autotools-dev (20220109.1) ... 208s Selecting previously unselected package automake. 208s Preparing to unpack .../005-automake_1%3a1.16.5-1.3ubuntu1_all.deb ... 208s Unpacking automake (1:1.16.5-1.3ubuntu1) ... 208s Selecting previously unselected package autopoint. 208s Preparing to unpack .../006-autopoint_0.22.5-2_all.deb ... 208s Unpacking autopoint (0.22.5-2) ... 208s Selecting previously unselected package libisl23:arm64. 208s Preparing to unpack .../007-libisl23_0.27-1_arm64.deb ... 208s Unpacking libisl23:arm64 (0.27-1) ... 208s Selecting previously unselected package libmpc3:arm64. 208s Preparing to unpack .../008-libmpc3_1.3.1-1build2_arm64.deb ... 208s Unpacking libmpc3:arm64 (1.3.1-1build2) ... 208s Selecting previously unselected package cpp-14-aarch64-linux-gnu. 208s Preparing to unpack .../009-cpp-14-aarch64-linux-gnu_14.2.0-9ubuntu1_arm64.deb ... 208s Unpacking cpp-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 208s Selecting previously unselected package cpp-14. 208s Preparing to unpack .../010-cpp-14_14.2.0-9ubuntu1_arm64.deb ... 208s Unpacking cpp-14 (14.2.0-9ubuntu1) ... 208s Selecting previously unselected package cpp-aarch64-linux-gnu. 208s Preparing to unpack .../011-cpp-aarch64-linux-gnu_4%3a14.1.0-2ubuntu1_arm64.deb ... 208s Unpacking cpp-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 208s Selecting previously unselected package cpp. 209s Preparing to unpack .../012-cpp_4%3a14.1.0-2ubuntu1_arm64.deb ... 209s Unpacking cpp (4:14.1.0-2ubuntu1) ... 209s Selecting previously unselected package libcc1-0:arm64. 209s Preparing to unpack .../013-libcc1-0_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libcc1-0:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libgomp1:arm64. 209s Preparing to unpack .../014-libgomp1_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libgomp1:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libitm1:arm64. 209s Preparing to unpack .../015-libitm1_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libitm1:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libasan8:arm64. 209s Preparing to unpack .../016-libasan8_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libasan8:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package liblsan0:arm64. 209s Preparing to unpack .../017-liblsan0_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking liblsan0:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libtsan2:arm64. 209s Preparing to unpack .../018-libtsan2_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libtsan2:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libubsan1:arm64. 209s Preparing to unpack .../019-libubsan1_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libubsan1:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libhwasan0:arm64. 209s Preparing to unpack .../020-libhwasan0_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libhwasan0:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package libgcc-14-dev:arm64. 209s Preparing to unpack .../021-libgcc-14-dev_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking libgcc-14-dev:arm64 (14.2.0-9ubuntu1) ... 209s Selecting previously unselected package gcc-14-aarch64-linux-gnu. 209s Preparing to unpack .../022-gcc-14-aarch64-linux-gnu_14.2.0-9ubuntu1_arm64.deb ... 209s Unpacking gcc-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 210s Selecting previously unselected package gcc-14. 210s Preparing to unpack .../023-gcc-14_14.2.0-9ubuntu1_arm64.deb ... 210s Unpacking gcc-14 (14.2.0-9ubuntu1) ... 210s Selecting previously unselected package gcc-aarch64-linux-gnu. 210s Preparing to unpack .../024-gcc-aarch64-linux-gnu_4%3a14.1.0-2ubuntu1_arm64.deb ... 210s Unpacking gcc-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 210s Selecting previously unselected package gcc. 210s Preparing to unpack .../025-gcc_4%3a14.1.0-2ubuntu1_arm64.deb ... 210s Unpacking gcc (4:14.1.0-2ubuntu1) ... 210s Selecting previously unselected package libstdc++-14-dev:arm64. 210s Preparing to unpack .../026-libstdc++-14-dev_14.2.0-9ubuntu1_arm64.deb ... 210s Unpacking libstdc++-14-dev:arm64 (14.2.0-9ubuntu1) ... 210s Selecting previously unselected package g++-14-aarch64-linux-gnu. 210s Preparing to unpack .../027-g++-14-aarch64-linux-gnu_14.2.0-9ubuntu1_arm64.deb ... 210s Unpacking g++-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 210s Selecting previously unselected package g++-14. 210s Preparing to unpack .../028-g++-14_14.2.0-9ubuntu1_arm64.deb ... 210s Unpacking g++-14 (14.2.0-9ubuntu1) ... 210s Selecting previously unselected package g++-aarch64-linux-gnu. 210s Preparing to unpack .../029-g++-aarch64-linux-gnu_4%3a14.1.0-2ubuntu1_arm64.deb ... 210s Unpacking g++-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 210s Selecting previously unselected package g++. 210s Preparing to unpack .../030-g++_4%3a14.1.0-2ubuntu1_arm64.deb ... 210s Unpacking g++ (4:14.1.0-2ubuntu1) ... 210s Selecting previously unselected package build-essential. 210s Preparing to unpack .../031-build-essential_12.10ubuntu1_arm64.deb ... 210s Unpacking build-essential (12.10ubuntu1) ... 210s Selecting previously unselected package libhttp-parser2.9:arm64. 210s Preparing to unpack .../032-libhttp-parser2.9_2.9.4-6build1_arm64.deb ... 210s Unpacking libhttp-parser2.9:arm64 (2.9.4-6build1) ... 210s Selecting previously unselected package libgit2-1.7:arm64. 210s Preparing to unpack .../033-libgit2-1.7_1.7.2+ds-1ubuntu3_arm64.deb ... 210s Unpacking libgit2-1.7:arm64 (1.7.2+ds-1ubuntu3) ... 211s Selecting previously unselected package libstd-rust-1.80:arm64. 211s Preparing to unpack .../034-libstd-rust-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_arm64.deb ... 211s Unpacking libstd-rust-1.80:arm64 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 211s Selecting previously unselected package libstd-rust-1.80-dev:arm64. 211s Preparing to unpack .../035-libstd-rust-1.80-dev_1.80.1+dfsg0ubuntu1-0ubuntu1_arm64.deb ... 211s Unpacking libstd-rust-1.80-dev:arm64 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 212s Selecting previously unselected package rustc-1.80. 212s Preparing to unpack .../036-rustc-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_arm64.deb ... 212s Unpacking rustc-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 212s Selecting previously unselected package cargo-1.80. 212s Preparing to unpack .../037-cargo-1.80_1.80.1+dfsg0ubuntu1-0ubuntu1_arm64.deb ... 212s Unpacking cargo-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 212s Selecting previously unselected package libjsoncpp25:arm64. 212s Preparing to unpack .../038-libjsoncpp25_1.9.5-6build1_arm64.deb ... 212s Unpacking libjsoncpp25:arm64 (1.9.5-6build1) ... 212s Selecting previously unselected package librhash0:arm64. 212s Preparing to unpack .../039-librhash0_1.4.3-3build1_arm64.deb ... 212s Unpacking librhash0:arm64 (1.4.3-3build1) ... 212s Selecting previously unselected package cmake-data. 212s Preparing to unpack .../040-cmake-data_3.30.3-1_all.deb ... 212s Unpacking cmake-data (3.30.3-1) ... 213s Selecting previously unselected package cmake. 213s Preparing to unpack .../041-cmake_3.30.3-1_arm64.deb ... 213s Unpacking cmake (3.30.3-1) ... 213s Selecting previously unselected package libdebhelper-perl. 213s Preparing to unpack .../042-libdebhelper-perl_13.20ubuntu1_all.deb ... 213s Unpacking libdebhelper-perl (13.20ubuntu1) ... 213s Selecting previously unselected package libtool. 213s Preparing to unpack .../043-libtool_2.4.7-8_all.deb ... 213s Unpacking libtool (2.4.7-8) ... 213s Selecting previously unselected package dh-autoreconf. 213s Preparing to unpack .../044-dh-autoreconf_20_all.deb ... 213s Unpacking dh-autoreconf (20) ... 213s Selecting previously unselected package libarchive-zip-perl. 213s Preparing to unpack .../045-libarchive-zip-perl_1.68-1_all.deb ... 213s Unpacking libarchive-zip-perl (1.68-1) ... 213s Selecting previously unselected package libfile-stripnondeterminism-perl. 213s Preparing to unpack .../046-libfile-stripnondeterminism-perl_1.14.0-1_all.deb ... 213s Unpacking libfile-stripnondeterminism-perl (1.14.0-1) ... 213s Selecting previously unselected package dh-strip-nondeterminism. 213s Preparing to unpack .../047-dh-strip-nondeterminism_1.14.0-1_all.deb ... 213s Unpacking dh-strip-nondeterminism (1.14.0-1) ... 213s Selecting previously unselected package debugedit. 213s Preparing to unpack .../048-debugedit_1%3a5.1-1_arm64.deb ... 213s Unpacking debugedit (1:5.1-1) ... 213s Selecting previously unselected package dwz. 213s Preparing to unpack .../049-dwz_0.15-1build6_arm64.deb ... 213s Unpacking dwz (0.15-1build6) ... 213s Selecting previously unselected package gettext. 213s Preparing to unpack .../050-gettext_0.22.5-2_arm64.deb ... 213s Unpacking gettext (0.22.5-2) ... 214s Selecting previously unselected package intltool-debian. 214s Preparing to unpack .../051-intltool-debian_0.35.0+20060710.6_all.deb ... 214s Unpacking intltool-debian (0.35.0+20060710.6) ... 214s Selecting previously unselected package po-debconf. 214s Preparing to unpack .../052-po-debconf_1.0.21+nmu1_all.deb ... 214s Unpacking po-debconf (1.0.21+nmu1) ... 214s Selecting previously unselected package debhelper. 214s Preparing to unpack .../053-debhelper_13.20ubuntu1_all.deb ... 214s Unpacking debhelper (13.20ubuntu1) ... 214s Selecting previously unselected package dh-python. 214s Preparing to unpack .../054-dh-python_6.20241024_all.deb ... 214s Unpacking dh-python (6.20241024) ... 214s Selecting previously unselected package fonts-dejavu-mono. 214s Preparing to unpack .../055-fonts-dejavu-mono_2.37-8_all.deb ... 214s Unpacking fonts-dejavu-mono (2.37-8) ... 214s Selecting previously unselected package fonts-dejavu-core. 214s Preparing to unpack .../056-fonts-dejavu-core_2.37-8_all.deb ... 214s Unpacking fonts-dejavu-core (2.37-8) ... 214s Selecting previously unselected package fontconfig-config. 214s Preparing to unpack .../057-fontconfig-config_2.15.0-1.1ubuntu2_arm64.deb ... 214s Unpacking fontconfig-config (2.15.0-1.1ubuntu2) ... 214s Selecting previously unselected package libbrotli-dev:arm64. 214s Preparing to unpack .../058-libbrotli-dev_1.1.0-2build3_arm64.deb ... 214s Unpacking libbrotli-dev:arm64 (1.1.0-2build3) ... 214s Selecting previously unselected package libbz2-dev:arm64. 214s Preparing to unpack .../059-libbz2-dev_1.0.8-6_arm64.deb ... 214s Unpacking libbz2-dev:arm64 (1.0.8-6) ... 214s Selecting previously unselected package libexpat1-dev:arm64. 214s Preparing to unpack .../060-libexpat1-dev_2.6.4-1_arm64.deb ... 214s Unpacking libexpat1-dev:arm64 (2.6.4-1) ... 215s Selecting previously unselected package libfontconfig1:arm64. 215s Preparing to unpack .../061-libfontconfig1_2.15.0-1.1ubuntu2_arm64.deb ... 215s Unpacking libfontconfig1:arm64 (2.15.0-1.1ubuntu2) ... 215s Selecting previously unselected package zlib1g-dev:arm64. 215s Preparing to unpack .../062-zlib1g-dev_1%3a1.3.dfsg+really1.3.1-1ubuntu1_arm64.deb ... 215s Unpacking zlib1g-dev:arm64 (1:1.3.dfsg+really1.3.1-1ubuntu1) ... 215s Selecting previously unselected package libpng-dev:arm64. 215s Preparing to unpack .../063-libpng-dev_1.6.44-2_arm64.deb ... 215s Unpacking libpng-dev:arm64 (1.6.44-2) ... 215s Selecting previously unselected package libfreetype-dev:arm64. 215s Preparing to unpack .../064-libfreetype-dev_2.13.3+dfsg-1_arm64.deb ... 215s Unpacking libfreetype-dev:arm64 (2.13.3+dfsg-1) ... 215s Selecting previously unselected package uuid-dev:arm64. 215s Preparing to unpack .../065-uuid-dev_2.40.2-1ubuntu1_arm64.deb ... 215s Unpacking uuid-dev:arm64 (2.40.2-1ubuntu1) ... 215s Selecting previously unselected package libpkgconf3:arm64. 215s Preparing to unpack .../066-libpkgconf3_1.8.1-4_arm64.deb ... 215s Unpacking libpkgconf3:arm64 (1.8.1-4) ... 215s Selecting previously unselected package pkgconf-bin. 215s Preparing to unpack .../067-pkgconf-bin_1.8.1-4_arm64.deb ... 215s Unpacking pkgconf-bin (1.8.1-4) ... 215s Selecting previously unselected package pkgconf:arm64. 215s Preparing to unpack .../068-pkgconf_1.8.1-4_arm64.deb ... 215s Unpacking pkgconf:arm64 (1.8.1-4) ... 215s Selecting previously unselected package libfontconfig-dev:arm64. 215s Preparing to unpack .../069-libfontconfig-dev_2.15.0-1.1ubuntu2_arm64.deb ... 215s Unpacking libfontconfig-dev:arm64 (2.15.0-1.1ubuntu2) ... 215s Selecting previously unselected package libpython3.12-dev:arm64. 215s Preparing to unpack .../070-libpython3.12-dev_3.12.7-3_arm64.deb ... 215s Unpacking libpython3.12-dev:arm64 (3.12.7-3) ... 215s Selecting previously unselected package libpython3-dev:arm64. 215s Preparing to unpack .../071-libpython3-dev_3.12.7-1_arm64.deb ... 215s Unpacking libpython3-dev:arm64 (3.12.7-1) ... 215s Selecting previously unselected package libpython3.13-stdlib:arm64. 215s Preparing to unpack .../072-libpython3.13-stdlib_3.13.0-2_arm64.deb ... 215s Unpacking libpython3.13-stdlib:arm64 (3.13.0-2) ... 215s Selecting previously unselected package libpython3.13:arm64. 215s Preparing to unpack .../073-libpython3.13_3.13.0-2_arm64.deb ... 215s Unpacking libpython3.13:arm64 (3.13.0-2) ... 215s Selecting previously unselected package libpython3.13-dev:arm64. 215s Preparing to unpack .../074-libpython3.13-dev_3.13.0-2_arm64.deb ... 215s Unpacking libpython3.13-dev:arm64 (3.13.0-2) ... 216s Selecting previously unselected package libpython3-all-dev:arm64. 216s Preparing to unpack .../075-libpython3-all-dev_3.12.7-1_arm64.deb ... 216s Unpacking libpython3-all-dev:arm64 (3.12.7-1) ... 216s Selecting previously unselected package librust-ab-glyph-rasterizer-dev:arm64. 216s Preparing to unpack .../076-librust-ab-glyph-rasterizer-dev_0.1.7-1_arm64.deb ... 216s Unpacking librust-ab-glyph-rasterizer-dev:arm64 (0.1.7-1) ... 216s Selecting previously unselected package librust-libm-dev:arm64. 216s Preparing to unpack .../077-librust-libm-dev_0.2.8-1_arm64.deb ... 216s Unpacking librust-libm-dev:arm64 (0.2.8-1) ... 216s Selecting previously unselected package librust-ab-glyph-rasterizer+libm-dev:arm64. 216s Preparing to unpack .../078-librust-ab-glyph-rasterizer+libm-dev_0.1.7-1_arm64.deb ... 216s Unpacking librust-ab-glyph-rasterizer+libm-dev:arm64 (0.1.7-1) ... 216s Selecting previously unselected package librust-core-maths-dev:arm64. 216s Preparing to unpack .../079-librust-core-maths-dev_0.1.0-2_arm64.deb ... 216s Unpacking librust-core-maths-dev:arm64 (0.1.0-2) ... 216s Selecting previously unselected package librust-ttf-parser-dev:arm64. 216s Preparing to unpack .../080-librust-ttf-parser-dev_0.24.1-1_arm64.deb ... 216s Unpacking librust-ttf-parser-dev:arm64 (0.24.1-1) ... 216s Selecting previously unselected package librust-owned-ttf-parser-dev:arm64. 216s Preparing to unpack .../081-librust-owned-ttf-parser-dev_0.24.0-1_arm64.deb ... 216s Unpacking librust-owned-ttf-parser-dev:arm64 (0.24.0-1) ... 216s Selecting previously unselected package librust-ab-glyph-dev:arm64. 216s Preparing to unpack .../082-librust-ab-glyph-dev_0.2.28-1_arm64.deb ... 216s Unpacking librust-ab-glyph-dev:arm64 (0.2.28-1) ... 216s Selecting previously unselected package librust-cfg-if-dev:arm64. 216s Preparing to unpack .../083-librust-cfg-if-dev_1.0.0-1_arm64.deb ... 216s Unpacking librust-cfg-if-dev:arm64 (1.0.0-1) ... 216s Selecting previously unselected package librust-cpp-demangle-dev:arm64. 216s Preparing to unpack .../084-librust-cpp-demangle-dev_0.4.0-1_arm64.deb ... 216s Unpacking librust-cpp-demangle-dev:arm64 (0.4.0-1) ... 216s Selecting previously unselected package librust-fallible-iterator-dev:arm64. 216s Preparing to unpack .../085-librust-fallible-iterator-dev_0.3.0-2_arm64.deb ... 216s Unpacking librust-fallible-iterator-dev:arm64 (0.3.0-2) ... 216s Selecting previously unselected package librust-unicode-ident-dev:arm64. 216s Preparing to unpack .../086-librust-unicode-ident-dev_1.0.13-1_arm64.deb ... 216s Unpacking librust-unicode-ident-dev:arm64 (1.0.13-1) ... 216s Selecting previously unselected package librust-proc-macro2-dev:arm64. 216s Preparing to unpack .../087-librust-proc-macro2-dev_1.0.86-1_arm64.deb ... 216s Unpacking librust-proc-macro2-dev:arm64 (1.0.86-1) ... 216s Selecting previously unselected package librust-quote-dev:arm64. 216s Preparing to unpack .../088-librust-quote-dev_1.0.37-1_arm64.deb ... 216s Unpacking librust-quote-dev:arm64 (1.0.37-1) ... 216s Selecting previously unselected package librust-syn-dev:arm64. 216s Preparing to unpack .../089-librust-syn-dev_2.0.85-1_arm64.deb ... 216s Unpacking librust-syn-dev:arm64 (2.0.85-1) ... 216s Selecting previously unselected package librust-derive-arbitrary-dev:arm64. 216s Preparing to unpack .../090-librust-derive-arbitrary-dev_1.3.2-1_arm64.deb ... 216s Unpacking librust-derive-arbitrary-dev:arm64 (1.3.2-1) ... 216s Selecting previously unselected package librust-arbitrary-dev:arm64. 216s Preparing to unpack .../091-librust-arbitrary-dev_1.3.2-1_arm64.deb ... 216s Unpacking librust-arbitrary-dev:arm64 (1.3.2-1) ... 216s Selecting previously unselected package librust-equivalent-dev:arm64. 216s Preparing to unpack .../092-librust-equivalent-dev_1.0.1-1_arm64.deb ... 216s Unpacking librust-equivalent-dev:arm64 (1.0.1-1) ... 216s Selecting previously unselected package librust-critical-section-dev:arm64. 216s Preparing to unpack .../093-librust-critical-section-dev_1.1.3-1_arm64.deb ... 216s Unpacking librust-critical-section-dev:arm64 (1.1.3-1) ... 216s Selecting previously unselected package librust-serde-derive-dev:arm64. 216s Preparing to unpack .../094-librust-serde-derive-dev_1.0.210-1_arm64.deb ... 216s Unpacking librust-serde-derive-dev:arm64 (1.0.210-1) ... 216s Selecting previously unselected package librust-serde-dev:arm64. 216s Preparing to unpack .../095-librust-serde-dev_1.0.210-2_arm64.deb ... 216s Unpacking librust-serde-dev:arm64 (1.0.210-2) ... 217s Selecting previously unselected package librust-portable-atomic-dev:arm64. 217s Preparing to unpack .../096-librust-portable-atomic-dev_1.9.0-4_arm64.deb ... 217s Unpacking librust-portable-atomic-dev:arm64 (1.9.0-4) ... 217s Selecting previously unselected package librust-rustc-std-workspace-core-dev:arm64. 217s Preparing to unpack .../097-librust-rustc-std-workspace-core-dev_1.0.0-1_arm64.deb ... 217s Unpacking librust-rustc-std-workspace-core-dev:arm64 (1.0.0-1) ... 217s Selecting previously unselected package librust-libc-dev:arm64. 217s Preparing to unpack .../098-librust-libc-dev_0.2.161-1_arm64.deb ... 217s Unpacking librust-libc-dev:arm64 (0.2.161-1) ... 217s Selecting previously unselected package librust-getrandom-dev:arm64. 217s Preparing to unpack .../099-librust-getrandom-dev_0.2.12-1_arm64.deb ... 217s Unpacking librust-getrandom-dev:arm64 (0.2.12-1) ... 217s Selecting previously unselected package librust-smallvec-dev:arm64. 217s Preparing to unpack .../100-librust-smallvec-dev_1.13.2-1_arm64.deb ... 217s Unpacking librust-smallvec-dev:arm64 (1.13.2-1) ... 217s Selecting previously unselected package librust-parking-lot-core-dev:arm64. 217s Preparing to unpack .../101-librust-parking-lot-core-dev_0.9.10-1_arm64.deb ... 217s Unpacking librust-parking-lot-core-dev:arm64 (0.9.10-1) ... 217s Selecting previously unselected package librust-once-cell-dev:arm64. 217s Preparing to unpack .../102-librust-once-cell-dev_1.20.2-1_arm64.deb ... 217s Unpacking librust-once-cell-dev:arm64 (1.20.2-1) ... 217s Selecting previously unselected package librust-crunchy-dev:arm64. 217s Preparing to unpack .../103-librust-crunchy-dev_0.2.2-1_arm64.deb ... 217s Unpacking librust-crunchy-dev:arm64 (0.2.2-1) ... 217s Selecting previously unselected package librust-tiny-keccak-dev:arm64. 217s Preparing to unpack .../104-librust-tiny-keccak-dev_2.0.2-1_arm64.deb ... 217s Unpacking librust-tiny-keccak-dev:arm64 (2.0.2-1) ... 217s Selecting previously unselected package librust-const-random-macro-dev:arm64. 217s Preparing to unpack .../105-librust-const-random-macro-dev_0.1.16-2_arm64.deb ... 217s Unpacking librust-const-random-macro-dev:arm64 (0.1.16-2) ... 217s Selecting previously unselected package librust-const-random-dev:arm64. 217s Preparing to unpack .../106-librust-const-random-dev_0.1.17-2_arm64.deb ... 217s Unpacking librust-const-random-dev:arm64 (0.1.17-2) ... 217s Selecting previously unselected package librust-version-check-dev:arm64. 217s Preparing to unpack .../107-librust-version-check-dev_0.9.5-1_arm64.deb ... 217s Unpacking librust-version-check-dev:arm64 (0.9.5-1) ... 217s Selecting previously unselected package librust-byteorder-dev:arm64. 217s Preparing to unpack .../108-librust-byteorder-dev_1.5.0-1_arm64.deb ... 217s Unpacking librust-byteorder-dev:arm64 (1.5.0-1) ... 217s Selecting previously unselected package librust-zerocopy-derive-dev:arm64. 217s Preparing to unpack .../109-librust-zerocopy-derive-dev_0.7.32-2_arm64.deb ... 217s Unpacking librust-zerocopy-derive-dev:arm64 (0.7.32-2) ... 217s Selecting previously unselected package librust-zerocopy-dev:arm64. 217s Preparing to unpack .../110-librust-zerocopy-dev_0.7.32-1_arm64.deb ... 217s Unpacking librust-zerocopy-dev:arm64 (0.7.32-1) ... 217s Selecting previously unselected package librust-ahash-dev. 217s Preparing to unpack .../111-librust-ahash-dev_0.8.11-8_all.deb ... 217s Unpacking librust-ahash-dev (0.8.11-8) ... 217s Selecting previously unselected package librust-allocator-api2-dev:arm64. 217s Preparing to unpack .../112-librust-allocator-api2-dev_0.2.16-1_arm64.deb ... 217s Unpacking librust-allocator-api2-dev:arm64 (0.2.16-1) ... 218s Selecting previously unselected package librust-compiler-builtins-dev:arm64. 218s Preparing to unpack .../113-librust-compiler-builtins-dev_0.1.101-1_arm64.deb ... 218s Unpacking librust-compiler-builtins-dev:arm64 (0.1.101-1) ... 218s Selecting previously unselected package librust-either-dev:arm64. 218s Preparing to unpack .../114-librust-either-dev_1.13.0-1_arm64.deb ... 218s Unpacking librust-either-dev:arm64 (1.13.0-1) ... 218s Selecting previously unselected package librust-crossbeam-utils-dev:arm64. 218s Preparing to unpack .../115-librust-crossbeam-utils-dev_0.8.19-1_arm64.deb ... 218s Unpacking librust-crossbeam-utils-dev:arm64 (0.8.19-1) ... 218s Selecting previously unselected package librust-crossbeam-epoch-dev:arm64. 218s Preparing to unpack .../116-librust-crossbeam-epoch-dev_0.9.18-1_arm64.deb ... 218s Unpacking librust-crossbeam-epoch-dev:arm64 (0.9.18-1) ... 218s Selecting previously unselected package librust-crossbeam-epoch+std-dev:arm64. 218s Preparing to unpack .../117-librust-crossbeam-epoch+std-dev_0.9.18-1_arm64.deb ... 218s Unpacking librust-crossbeam-epoch+std-dev:arm64 (0.9.18-1) ... 218s Selecting previously unselected package librust-crossbeam-deque-dev:arm64. 218s Preparing to unpack .../118-librust-crossbeam-deque-dev_0.8.5-1_arm64.deb ... 218s Unpacking librust-crossbeam-deque-dev:arm64 (0.8.5-1) ... 218s Selecting previously unselected package librust-rayon-core-dev:arm64. 218s Preparing to unpack .../119-librust-rayon-core-dev_1.12.1-1_arm64.deb ... 218s Unpacking librust-rayon-core-dev:arm64 (1.12.1-1) ... 218s Selecting previously unselected package librust-rayon-dev:arm64. 218s Preparing to unpack .../120-librust-rayon-dev_1.10.0-1_arm64.deb ... 218s Unpacking librust-rayon-dev:arm64 (1.10.0-1) ... 218s Selecting previously unselected package librust-hashbrown-dev:arm64. 218s Preparing to unpack .../121-librust-hashbrown-dev_0.14.5-5_arm64.deb ... 218s Unpacking librust-hashbrown-dev:arm64 (0.14.5-5) ... 218s Selecting previously unselected package librust-indexmap-dev:arm64. 218s Preparing to unpack .../122-librust-indexmap-dev_2.2.6-1_arm64.deb ... 218s Unpacking librust-indexmap-dev:arm64 (2.2.6-1) ... 218s Selecting previously unselected package librust-stable-deref-trait-dev:arm64. 218s Preparing to unpack .../123-librust-stable-deref-trait-dev_1.2.0-1_arm64.deb ... 218s Unpacking librust-stable-deref-trait-dev:arm64 (1.2.0-1) ... 218s Selecting previously unselected package librust-gimli-dev:arm64. 218s Preparing to unpack .../124-librust-gimli-dev_0.28.1-2_arm64.deb ... 218s Unpacking librust-gimli-dev:arm64 (0.28.1-2) ... 218s Selecting previously unselected package librust-memmap2-dev:arm64. 218s Preparing to unpack .../125-librust-memmap2-dev_0.9.3-1_arm64.deb ... 218s Unpacking librust-memmap2-dev:arm64 (0.9.3-1) ... 218s Selecting previously unselected package librust-crc32fast-dev:arm64. 218s Preparing to unpack .../126-librust-crc32fast-dev_1.4.2-1_arm64.deb ... 218s Unpacking librust-crc32fast-dev:arm64 (1.4.2-1) ... 218s Selecting previously unselected package pkg-config:arm64. 218s Preparing to unpack .../127-pkg-config_1.8.1-4_arm64.deb ... 218s Unpacking pkg-config:arm64 (1.8.1-4) ... 218s Selecting previously unselected package librust-pkg-config-dev:arm64. 218s Preparing to unpack .../128-librust-pkg-config-dev_0.3.27-1_arm64.deb ... 218s Unpacking librust-pkg-config-dev:arm64 (0.3.27-1) ... 218s Selecting previously unselected package librust-libz-sys-dev:arm64. 218s Preparing to unpack .../129-librust-libz-sys-dev_1.1.20-1_arm64.deb ... 218s Unpacking librust-libz-sys-dev:arm64 (1.1.20-1) ... 219s Selecting previously unselected package librust-adler-dev:arm64. 219s Preparing to unpack .../130-librust-adler-dev_1.0.2-2_arm64.deb ... 219s Unpacking librust-adler-dev:arm64 (1.0.2-2) ... 219s Selecting previously unselected package librust-miniz-oxide-dev:arm64. 219s Preparing to unpack .../131-librust-miniz-oxide-dev_0.7.1-1_arm64.deb ... 219s Unpacking librust-miniz-oxide-dev:arm64 (0.7.1-1) ... 219s Selecting previously unselected package librust-flate2-dev:arm64. 219s Preparing to unpack .../132-librust-flate2-dev_1.0.34-1_arm64.deb ... 219s Unpacking librust-flate2-dev:arm64 (1.0.34-1) ... 219s Selecting previously unselected package librust-sval-derive-dev:arm64. 219s Preparing to unpack .../133-librust-sval-derive-dev_2.6.1-2_arm64.deb ... 219s Unpacking librust-sval-derive-dev:arm64 (2.6.1-2) ... 219s Selecting previously unselected package librust-sval-dev:arm64. 219s Preparing to unpack .../134-librust-sval-dev_2.6.1-2_arm64.deb ... 219s Unpacking librust-sval-dev:arm64 (2.6.1-2) ... 219s Selecting previously unselected package librust-sval-ref-dev:arm64. 219s Preparing to unpack .../135-librust-sval-ref-dev_2.6.1-1_arm64.deb ... 219s Unpacking librust-sval-ref-dev:arm64 (2.6.1-1) ... 219s Selecting previously unselected package librust-erased-serde-dev:arm64. 219s Preparing to unpack .../136-librust-erased-serde-dev_0.3.31-1_arm64.deb ... 219s Unpacking librust-erased-serde-dev:arm64 (0.3.31-1) ... 219s Selecting previously unselected package librust-serde-fmt-dev. 219s Preparing to unpack .../137-librust-serde-fmt-dev_1.0.3-3_all.deb ... 219s Unpacking librust-serde-fmt-dev (1.0.3-3) ... 219s Selecting previously unselected package librust-syn-1-dev:arm64. 219s Preparing to unpack .../138-librust-syn-1-dev_1.0.109-3_arm64.deb ... 219s Unpacking librust-syn-1-dev:arm64 (1.0.109-3) ... 219s Selecting previously unselected package librust-no-panic-dev:arm64. 219s Preparing to unpack .../139-librust-no-panic-dev_0.1.13-1_arm64.deb ... 219s Unpacking librust-no-panic-dev:arm64 (0.1.13-1) ... 219s Selecting previously unselected package librust-itoa-dev:arm64. 219s Preparing to unpack .../140-librust-itoa-dev_1.0.9-1_arm64.deb ... 219s Unpacking librust-itoa-dev:arm64 (1.0.9-1) ... 219s Selecting previously unselected package librust-ryu-dev:arm64. 219s Preparing to unpack .../141-librust-ryu-dev_1.0.15-1_arm64.deb ... 219s Unpacking librust-ryu-dev:arm64 (1.0.15-1) ... 219s Selecting previously unselected package librust-serde-json-dev:arm64. 219s Preparing to unpack .../142-librust-serde-json-dev_1.0.128-1_arm64.deb ... 219s Unpacking librust-serde-json-dev:arm64 (1.0.128-1) ... 219s Selecting previously unselected package librust-serde-test-dev:arm64. 219s Preparing to unpack .../143-librust-serde-test-dev_1.0.171-1_arm64.deb ... 219s Unpacking librust-serde-test-dev:arm64 (1.0.171-1) ... 219s Selecting previously unselected package librust-value-bag-serde1-dev:arm64. 219s Preparing to unpack .../144-librust-value-bag-serde1-dev_1.9.0-1_arm64.deb ... 219s Unpacking librust-value-bag-serde1-dev:arm64 (1.9.0-1) ... 219s Selecting previously unselected package librust-sval-buffer-dev:arm64. 219s Preparing to unpack .../145-librust-sval-buffer-dev_2.6.1-1_arm64.deb ... 219s Unpacking librust-sval-buffer-dev:arm64 (2.6.1-1) ... 219s Selecting previously unselected package librust-sval-dynamic-dev:arm64. 219s Preparing to unpack .../146-librust-sval-dynamic-dev_2.6.1-1_arm64.deb ... 219s Unpacking librust-sval-dynamic-dev:arm64 (2.6.1-1) ... 219s Selecting previously unselected package librust-sval-fmt-dev:arm64. 219s Preparing to unpack .../147-librust-sval-fmt-dev_2.6.1-1_arm64.deb ... 219s Unpacking librust-sval-fmt-dev:arm64 (2.6.1-1) ... 219s Selecting previously unselected package librust-sval-serde-dev:arm64. 219s Preparing to unpack .../148-librust-sval-serde-dev_2.6.1-1_arm64.deb ... 219s Unpacking librust-sval-serde-dev:arm64 (2.6.1-1) ... 219s Selecting previously unselected package librust-value-bag-sval2-dev:arm64. 219s Preparing to unpack .../149-librust-value-bag-sval2-dev_1.9.0-1_arm64.deb ... 219s Unpacking librust-value-bag-sval2-dev:arm64 (1.9.0-1) ... 219s Selecting previously unselected package librust-value-bag-dev:arm64. 219s Preparing to unpack .../150-librust-value-bag-dev_1.9.0-1_arm64.deb ... 219s Unpacking librust-value-bag-dev:arm64 (1.9.0-1) ... 220s Selecting previously unselected package librust-log-dev:arm64. 220s Preparing to unpack .../151-librust-log-dev_0.4.22-1_arm64.deb ... 220s Unpacking librust-log-dev:arm64 (0.4.22-1) ... 220s Selecting previously unselected package librust-memchr-dev:arm64. 220s Preparing to unpack .../152-librust-memchr-dev_2.7.4-1_arm64.deb ... 220s Unpacking librust-memchr-dev:arm64 (2.7.4-1) ... 220s Selecting previously unselected package librust-ppv-lite86-dev:arm64. 220s Preparing to unpack .../153-librust-ppv-lite86-dev_0.2.16-1_arm64.deb ... 220s Unpacking librust-ppv-lite86-dev:arm64 (0.2.16-1) ... 220s Selecting previously unselected package librust-rand-core-dev:arm64. 220s Preparing to unpack .../154-librust-rand-core-dev_0.6.4-2_arm64.deb ... 220s Unpacking librust-rand-core-dev:arm64 (0.6.4-2) ... 220s Selecting previously unselected package librust-rand-chacha-dev:arm64. 220s Preparing to unpack .../155-librust-rand-chacha-dev_0.3.1-2_arm64.deb ... 220s Unpacking librust-rand-chacha-dev:arm64 (0.3.1-2) ... 220s Selecting previously unselected package librust-rand-core+getrandom-dev:arm64. 220s Preparing to unpack .../156-librust-rand-core+getrandom-dev_0.6.4-2_arm64.deb ... 220s Unpacking librust-rand-core+getrandom-dev:arm64 (0.6.4-2) ... 220s Selecting previously unselected package librust-rand-core+serde-dev:arm64. 220s Preparing to unpack .../157-librust-rand-core+serde-dev_0.6.4-2_arm64.deb ... 220s Unpacking librust-rand-core+serde-dev:arm64 (0.6.4-2) ... 220s Selecting previously unselected package librust-rand-core+std-dev:arm64. 220s Preparing to unpack .../158-librust-rand-core+std-dev_0.6.4-2_arm64.deb ... 220s Unpacking librust-rand-core+std-dev:arm64 (0.6.4-2) ... 220s Selecting previously unselected package librust-rand-dev:arm64. 220s Preparing to unpack .../159-librust-rand-dev_0.8.5-1_arm64.deb ... 220s Unpacking librust-rand-dev:arm64 (0.8.5-1) ... 220s Selecting previously unselected package librust-unicode-segmentation-dev:arm64. 220s Preparing to unpack .../160-librust-unicode-segmentation-dev_1.11.0-1_arm64.deb ... 220s Unpacking librust-unicode-segmentation-dev:arm64 (1.11.0-1) ... 220s Selecting previously unselected package librust-convert-case-dev:arm64. 220s Preparing to unpack .../161-librust-convert-case-dev_0.6.0-2_arm64.deb ... 220s Unpacking librust-convert-case-dev:arm64 (0.6.0-2) ... 220s Selecting previously unselected package librust-semver-dev:arm64. 220s Preparing to unpack .../162-librust-semver-dev_1.0.23-1_arm64.deb ... 220s Unpacking librust-semver-dev:arm64 (1.0.23-1) ... 220s Selecting previously unselected package librust-rustc-version-dev:arm64. 220s Preparing to unpack .../163-librust-rustc-version-dev_0.4.0-1_arm64.deb ... 220s Unpacking librust-rustc-version-dev:arm64 (0.4.0-1) ... 220s Selecting previously unselected package librust-derive-more-0.99-dev:arm64. 220s Preparing to unpack .../164-librust-derive-more-0.99-dev_0.99.18-2_arm64.deb ... 220s Unpacking librust-derive-more-0.99-dev:arm64 (0.99.18-2) ... 220s Selecting previously unselected package librust-cfg-if-0.1-dev:arm64. 220s Preparing to unpack .../165-librust-cfg-if-0.1-dev_0.1.10-3_arm64.deb ... 220s Unpacking librust-cfg-if-0.1-dev:arm64 (0.1.10-3) ... 220s Selecting previously unselected package librust-blobby-dev:arm64. 220s Preparing to unpack .../166-librust-blobby-dev_0.3.1-1_arm64.deb ... 220s Unpacking librust-blobby-dev:arm64 (0.3.1-1) ... 220s Selecting previously unselected package librust-typenum-dev:arm64. 220s Preparing to unpack .../167-librust-typenum-dev_1.17.0-2_arm64.deb ... 220s Unpacking librust-typenum-dev:arm64 (1.17.0-2) ... 220s Selecting previously unselected package librust-zeroize-derive-dev:arm64. 220s Preparing to unpack .../168-librust-zeroize-derive-dev_1.4.2-1_arm64.deb ... 220s Unpacking librust-zeroize-derive-dev:arm64 (1.4.2-1) ... 220s Selecting previously unselected package librust-zeroize-dev:arm64. 220s Preparing to unpack .../169-librust-zeroize-dev_1.8.1-1_arm64.deb ... 220s Unpacking librust-zeroize-dev:arm64 (1.8.1-1) ... 220s Selecting previously unselected package librust-generic-array-dev:arm64. 220s Preparing to unpack .../170-librust-generic-array-dev_0.14.7-1_arm64.deb ... 220s Unpacking librust-generic-array-dev:arm64 (0.14.7-1) ... 220s Selecting previously unselected package librust-block-buffer-dev:arm64. 221s Preparing to unpack .../171-librust-block-buffer-dev_0.10.2-2_arm64.deb ... 221s Unpacking librust-block-buffer-dev:arm64 (0.10.2-2) ... 221s Selecting previously unselected package librust-const-oid-dev:arm64. 221s Preparing to unpack .../172-librust-const-oid-dev_0.9.3-1_arm64.deb ... 221s Unpacking librust-const-oid-dev:arm64 (0.9.3-1) ... 221s Selecting previously unselected package librust-crypto-common-dev:arm64. 221s Preparing to unpack .../173-librust-crypto-common-dev_0.1.6-1_arm64.deb ... 221s Unpacking librust-crypto-common-dev:arm64 (0.1.6-1) ... 221s Selecting previously unselected package librust-subtle-dev:arm64. 221s Preparing to unpack .../174-librust-subtle-dev_2.6.1-1_arm64.deb ... 221s Unpacking librust-subtle-dev:arm64 (2.6.1-1) ... 221s Selecting previously unselected package librust-digest-dev:arm64. 221s Preparing to unpack .../175-librust-digest-dev_0.10.7-2_arm64.deb ... 221s Unpacking librust-digest-dev:arm64 (0.10.7-2) ... 221s Selecting previously unselected package librust-static-assertions-dev:arm64. 221s Preparing to unpack .../176-librust-static-assertions-dev_1.1.0-1_arm64.deb ... 221s Unpacking librust-static-assertions-dev:arm64 (1.1.0-1) ... 221s Selecting previously unselected package librust-twox-hash-dev:arm64. 221s Preparing to unpack .../177-librust-twox-hash-dev_1.6.3-1_arm64.deb ... 221s Unpacking librust-twox-hash-dev:arm64 (1.6.3-1) ... 221s Selecting previously unselected package librust-ruzstd-dev:arm64. 221s Preparing to unpack .../178-librust-ruzstd-dev_0.5.0-1_arm64.deb ... 221s Unpacking librust-ruzstd-dev:arm64 (0.5.0-1) ... 221s Selecting previously unselected package librust-object-dev:arm64. 221s Preparing to unpack .../179-librust-object-dev_0.32.2-1_arm64.deb ... 221s Unpacking librust-object-dev:arm64 (0.32.2-1) ... 221s Selecting previously unselected package librust-rustc-demangle-dev:arm64. 221s Preparing to unpack .../180-librust-rustc-demangle-dev_0.1.21-1_arm64.deb ... 221s Unpacking librust-rustc-demangle-dev:arm64 (0.1.21-1) ... 221s Selecting previously unselected package librust-addr2line-dev:arm64. 221s Preparing to unpack .../181-librust-addr2line-dev_0.21.0-2_arm64.deb ... 221s Unpacking librust-addr2line-dev:arm64 (0.21.0-2) ... 221s Selecting previously unselected package librust-aho-corasick-dev:arm64. 221s Preparing to unpack .../182-librust-aho-corasick-dev_1.1.3-1_arm64.deb ... 221s Unpacking librust-aho-corasick-dev:arm64 (1.1.3-1) ... 221s Selecting previously unselected package librust-bitflags-1-dev:arm64. 221s Preparing to unpack .../183-librust-bitflags-1-dev_1.3.2-5_arm64.deb ... 221s Unpacking librust-bitflags-1-dev:arm64 (1.3.2-5) ... 221s Selecting previously unselected package librust-anes-dev:arm64. 221s Preparing to unpack .../184-librust-anes-dev_0.1.6-1_arm64.deb ... 221s Unpacking librust-anes-dev:arm64 (0.1.6-1) ... 221s Selecting previously unselected package librust-anstyle-dev:arm64. 221s Preparing to unpack .../185-librust-anstyle-dev_1.0.8-1_arm64.deb ... 221s Unpacking librust-anstyle-dev:arm64 (1.0.8-1) ... 221s Selecting previously unselected package librust-arrayvec-dev:arm64. 221s Preparing to unpack .../186-librust-arrayvec-dev_0.7.4-2_arm64.deb ... 221s Unpacking librust-arrayvec-dev:arm64 (0.7.4-2) ... 221s Selecting previously unselected package librust-utf8parse-dev:arm64. 221s Preparing to unpack .../187-librust-utf8parse-dev_0.2.1-1_arm64.deb ... 221s Unpacking librust-utf8parse-dev:arm64 (0.2.1-1) ... 221s Selecting previously unselected package librust-anstyle-parse-dev:arm64. 221s Preparing to unpack .../188-librust-anstyle-parse-dev_0.2.1-1_arm64.deb ... 221s Unpacking librust-anstyle-parse-dev:arm64 (0.2.1-1) ... 221s Selecting previously unselected package librust-anstyle-query-dev:arm64. 222s Preparing to unpack .../189-librust-anstyle-query-dev_1.0.0-1_arm64.deb ... 222s Unpacking librust-anstyle-query-dev:arm64 (1.0.0-1) ... 222s Selecting previously unselected package librust-colorchoice-dev:arm64. 222s Preparing to unpack .../190-librust-colorchoice-dev_1.0.0-1_arm64.deb ... 222s Unpacking librust-colorchoice-dev:arm64 (1.0.0-1) ... 222s Selecting previously unselected package librust-anstream-dev:arm64. 222s Preparing to unpack .../191-librust-anstream-dev_0.6.15-1_arm64.deb ... 222s Unpacking librust-anstream-dev:arm64 (0.6.15-1) ... 222s Selecting previously unselected package librust-jobserver-dev:arm64. 222s Preparing to unpack .../192-librust-jobserver-dev_0.1.32-1_arm64.deb ... 222s Unpacking librust-jobserver-dev:arm64 (0.1.32-1) ... 222s Selecting previously unselected package librust-shlex-dev:arm64. 222s Preparing to unpack .../193-librust-shlex-dev_1.3.0-1_arm64.deb ... 222s Unpacking librust-shlex-dev:arm64 (1.3.0-1) ... 222s Selecting previously unselected package librust-cc-dev:arm64. 222s Preparing to unpack .../194-librust-cc-dev_1.1.14-1_arm64.deb ... 222s Unpacking librust-cc-dev:arm64 (1.1.14-1) ... 222s Selecting previously unselected package librust-backtrace-dev:arm64. 222s Preparing to unpack .../195-librust-backtrace-dev_0.3.69-2_arm64.deb ... 222s Unpacking librust-backtrace-dev:arm64 (0.3.69-2) ... 222s Selecting previously unselected package librust-anyhow-dev:arm64. 222s Preparing to unpack .../196-librust-anyhow-dev_1.0.86-1_arm64.deb ... 222s Unpacking librust-anyhow-dev:arm64 (1.0.86-1) ... 222s Selecting previously unselected package librust-bytecheck-derive-dev:arm64. 222s Preparing to unpack .../197-librust-bytecheck-derive-dev_0.6.12-1_arm64.deb ... 222s Unpacking librust-bytecheck-derive-dev:arm64 (0.6.12-1) ... 222s Selecting previously unselected package librust-ptr-meta-derive-dev:arm64. 222s Preparing to unpack .../198-librust-ptr-meta-derive-dev_0.1.4-1_arm64.deb ... 222s Unpacking librust-ptr-meta-derive-dev:arm64 (0.1.4-1) ... 222s Selecting previously unselected package librust-ptr-meta-dev:arm64. 222s Preparing to unpack .../199-librust-ptr-meta-dev_0.1.4-1_arm64.deb ... 222s Unpacking librust-ptr-meta-dev:arm64 (0.1.4-1) ... 222s Selecting previously unselected package librust-simdutf8-dev:arm64. 222s Preparing to unpack .../200-librust-simdutf8-dev_0.1.4-4_arm64.deb ... 222s Unpacking librust-simdutf8-dev:arm64 (0.1.4-4) ... 222s Selecting previously unselected package librust-bytemuck-derive-dev:arm64. 222s Preparing to unpack .../201-librust-bytemuck-derive-dev_1.5.0-2_arm64.deb ... 222s Unpacking librust-bytemuck-derive-dev:arm64 (1.5.0-2) ... 222s Selecting previously unselected package librust-bytemuck-dev:arm64. 222s Preparing to unpack .../202-librust-bytemuck-dev_1.14.0-1_arm64.deb ... 222s Unpacking librust-bytemuck-dev:arm64 (1.14.0-1) ... 222s Selecting previously unselected package librust-atomic-dev:arm64. 222s Preparing to unpack .../203-librust-atomic-dev_0.6.0-1_arm64.deb ... 222s Unpacking librust-atomic-dev:arm64 (0.6.0-1) ... 222s Selecting previously unselected package librust-md5-asm-dev:arm64. 222s Preparing to unpack .../204-librust-md5-asm-dev_0.5.0-2_arm64.deb ... 222s Unpacking librust-md5-asm-dev:arm64 (0.5.0-2) ... 222s Selecting previously unselected package librust-md-5-dev:arm64. 222s Preparing to unpack .../205-librust-md-5-dev_0.10.6-1_arm64.deb ... 222s Unpacking librust-md-5-dev:arm64 (0.10.6-1) ... 222s Selecting previously unselected package librust-cpufeatures-dev:arm64. 222s Preparing to unpack .../206-librust-cpufeatures-dev_0.2.11-1_arm64.deb ... 222s Unpacking librust-cpufeatures-dev:arm64 (0.2.11-1) ... 222s Selecting previously unselected package librust-sha1-asm-dev:arm64. 222s Preparing to unpack .../207-librust-sha1-asm-dev_0.5.1-2_arm64.deb ... 222s Unpacking librust-sha1-asm-dev:arm64 (0.5.1-2) ... 222s Selecting previously unselected package librust-sha1-dev:arm64. 222s Preparing to unpack .../208-librust-sha1-dev_0.10.6-1_arm64.deb ... 222s Unpacking librust-sha1-dev:arm64 (0.10.6-1) ... 222s Selecting previously unselected package librust-slog-dev:arm64. 223s Preparing to unpack .../209-librust-slog-dev_2.7.0-1_arm64.deb ... 223s Unpacking librust-slog-dev:arm64 (2.7.0-1) ... 223s Selecting previously unselected package librust-uuid-dev:arm64. 223s Preparing to unpack .../210-librust-uuid-dev_1.10.0-1_arm64.deb ... 223s Unpacking librust-uuid-dev:arm64 (1.10.0-1) ... 223s Selecting previously unselected package librust-bytecheck-dev:arm64. 223s Preparing to unpack .../211-librust-bytecheck-dev_0.6.12-1_arm64.deb ... 223s Unpacking librust-bytecheck-dev:arm64 (0.6.12-1) ... 223s Selecting previously unselected package librust-autocfg-dev:arm64. 223s Preparing to unpack .../212-librust-autocfg-dev_1.1.0-1_arm64.deb ... 223s Unpacking librust-autocfg-dev:arm64 (1.1.0-1) ... 223s Selecting previously unselected package librust-num-traits-dev:arm64. 223s Preparing to unpack .../213-librust-num-traits-dev_0.2.19-2_arm64.deb ... 223s Unpacking librust-num-traits-dev:arm64 (0.2.19-2) ... 223s Selecting previously unselected package librust-funty-dev:arm64. 223s Preparing to unpack .../214-librust-funty-dev_2.0.0-1_arm64.deb ... 223s Unpacking librust-funty-dev:arm64 (2.0.0-1) ... 223s Selecting previously unselected package librust-radium-dev:arm64. 223s Preparing to unpack .../215-librust-radium-dev_1.1.0-1_arm64.deb ... 223s Unpacking librust-radium-dev:arm64 (1.1.0-1) ... 223s Selecting previously unselected package librust-tap-dev:arm64. 223s Preparing to unpack .../216-librust-tap-dev_1.0.1-1_arm64.deb ... 223s Unpacking librust-tap-dev:arm64 (1.0.1-1) ... 223s Selecting previously unselected package librust-traitobject-dev:arm64. 223s Preparing to unpack .../217-librust-traitobject-dev_0.1.0-1_arm64.deb ... 223s Unpacking librust-traitobject-dev:arm64 (0.1.0-1) ... 223s Selecting previously unselected package librust-unsafe-any-dev:arm64. 223s Preparing to unpack .../218-librust-unsafe-any-dev_0.4.2-2_arm64.deb ... 223s Unpacking librust-unsafe-any-dev:arm64 (0.4.2-2) ... 223s Selecting previously unselected package librust-typemap-dev:arm64. 223s Preparing to unpack .../219-librust-typemap-dev_0.3.3-2_arm64.deb ... 223s Unpacking librust-typemap-dev:arm64 (0.3.3-2) ... 223s Selecting previously unselected package librust-wyz-dev:arm64. 223s Preparing to unpack .../220-librust-wyz-dev_0.5.1-1_arm64.deb ... 223s Unpacking librust-wyz-dev:arm64 (0.5.1-1) ... 223s Selecting previously unselected package librust-bitvec-dev:arm64. 223s Preparing to unpack .../221-librust-bitvec-dev_1.0.1-1_arm64.deb ... 223s Unpacking librust-bitvec-dev:arm64 (1.0.1-1) ... 223s Selecting previously unselected package librust-bytes-dev:arm64. 223s Preparing to unpack .../222-librust-bytes-dev_1.8.0-1_arm64.deb ... 223s Unpacking librust-bytes-dev:arm64 (1.8.0-1) ... 223s Selecting previously unselected package librust-rend-dev:arm64. 223s Preparing to unpack .../223-librust-rend-dev_0.4.0-1_arm64.deb ... 223s Unpacking librust-rend-dev:arm64 (0.4.0-1) ... 223s Selecting previously unselected package librust-rkyv-derive-dev:arm64. 223s Preparing to unpack .../224-librust-rkyv-derive-dev_0.7.44-1_arm64.deb ... 223s Unpacking librust-rkyv-derive-dev:arm64 (0.7.44-1) ... 223s Selecting previously unselected package librust-seahash-dev:arm64. 223s Preparing to unpack .../225-librust-seahash-dev_4.1.0-1_arm64.deb ... 223s Unpacking librust-seahash-dev:arm64 (4.1.0-1) ... 223s Selecting previously unselected package librust-smol-str-dev:arm64. 223s Preparing to unpack .../226-librust-smol-str-dev_0.2.0-1_arm64.deb ... 223s Unpacking librust-smol-str-dev:arm64 (0.2.0-1) ... 223s Selecting previously unselected package librust-tinyvec-dev:arm64. 223s Preparing to unpack .../227-librust-tinyvec-dev_1.6.0-2_arm64.deb ... 223s Unpacking librust-tinyvec-dev:arm64 (1.6.0-2) ... 223s Selecting previously unselected package librust-tinyvec-macros-dev:arm64. 224s Preparing to unpack .../228-librust-tinyvec-macros-dev_0.1.0-1_arm64.deb ... 224s Unpacking librust-tinyvec-macros-dev:arm64 (0.1.0-1) ... 224s Selecting previously unselected package librust-tinyvec+tinyvec-macros-dev:arm64. 224s Preparing to unpack .../229-librust-tinyvec+tinyvec-macros-dev_1.6.0-2_arm64.deb ... 224s Unpacking librust-tinyvec+tinyvec-macros-dev:arm64 (1.6.0-2) ... 224s Selecting previously unselected package librust-rkyv-dev:arm64. 224s Preparing to unpack .../230-librust-rkyv-dev_0.7.44-1_arm64.deb ... 224s Unpacking librust-rkyv-dev:arm64 (0.7.44-1) ... 224s Selecting previously unselected package librust-num-complex-dev:arm64. 224s Preparing to unpack .../231-librust-num-complex-dev_0.4.6-2_arm64.deb ... 224s Unpacking librust-num-complex-dev:arm64 (0.4.6-2) ... 224s Selecting previously unselected package librust-approx-dev:arm64. 224s Preparing to unpack .../232-librust-approx-dev_0.5.1-1_arm64.deb ... 224s Unpacking librust-approx-dev:arm64 (0.5.1-1) ... 224s Selecting previously unselected package librust-array-init-dev:arm64. 224s Preparing to unpack .../233-librust-array-init-dev_2.0.1-1_arm64.deb ... 224s Unpacking librust-array-init-dev:arm64 (2.0.1-1) ... 224s Selecting previously unselected package librust-async-attributes-dev. 224s Preparing to unpack .../234-librust-async-attributes-dev_1.1.2-6_all.deb ... 224s Unpacking librust-async-attributes-dev (1.1.2-6) ... 224s Selecting previously unselected package librust-concurrent-queue-dev:arm64. 224s Preparing to unpack .../235-librust-concurrent-queue-dev_2.5.0-4_arm64.deb ... 224s Unpacking librust-concurrent-queue-dev:arm64 (2.5.0-4) ... 224s Selecting previously unselected package librust-parking-dev:arm64. 224s Preparing to unpack .../236-librust-parking-dev_2.2.0-1_arm64.deb ... 224s Unpacking librust-parking-dev:arm64 (2.2.0-1) ... 224s Selecting previously unselected package librust-pin-project-lite-dev:arm64. 224s Preparing to unpack .../237-librust-pin-project-lite-dev_0.2.13-1_arm64.deb ... 224s Unpacking librust-pin-project-lite-dev:arm64 (0.2.13-1) ... 224s Selecting previously unselected package librust-event-listener-dev. 224s Preparing to unpack .../238-librust-event-listener-dev_5.3.1-8_all.deb ... 224s Unpacking librust-event-listener-dev (5.3.1-8) ... 224s Selecting previously unselected package librust-event-listener-strategy-dev:arm64. 224s Preparing to unpack .../239-librust-event-listener-strategy-dev_0.5.2-3_arm64.deb ... 224s Unpacking librust-event-listener-strategy-dev:arm64 (0.5.2-3) ... 224s Selecting previously unselected package librust-futures-core-dev:arm64. 224s Preparing to unpack .../240-librust-futures-core-dev_0.3.30-1_arm64.deb ... 224s Unpacking librust-futures-core-dev:arm64 (0.3.30-1) ... 224s Selecting previously unselected package librust-async-channel-dev. 224s Preparing to unpack .../241-librust-async-channel-dev_2.3.1-8_all.deb ... 224s Unpacking librust-async-channel-dev (2.3.1-8) ... 224s Selecting previously unselected package librust-async-task-dev. 224s Preparing to unpack .../242-librust-async-task-dev_4.7.1-3_all.deb ... 224s Unpacking librust-async-task-dev (4.7.1-3) ... 224s Selecting previously unselected package librust-fastrand-dev:arm64. 224s Preparing to unpack .../243-librust-fastrand-dev_2.1.1-1_arm64.deb ... 224s Unpacking librust-fastrand-dev:arm64 (2.1.1-1) ... 224s Selecting previously unselected package librust-futures-io-dev:arm64. 224s Preparing to unpack .../244-librust-futures-io-dev_0.3.31-1_arm64.deb ... 224s Unpacking librust-futures-io-dev:arm64 (0.3.31-1) ... 224s Selecting previously unselected package librust-futures-lite-dev:arm64. 224s Preparing to unpack .../245-librust-futures-lite-dev_2.3.0-2_arm64.deb ... 224s Unpacking librust-futures-lite-dev:arm64 (2.3.0-2) ... 224s Selecting previously unselected package librust-slab-dev:arm64. 224s Preparing to unpack .../246-librust-slab-dev_0.4.9-1_arm64.deb ... 224s Unpacking librust-slab-dev:arm64 (0.4.9-1) ... 224s Selecting previously unselected package librust-async-executor-dev. 224s Preparing to unpack .../247-librust-async-executor-dev_1.13.1-1_all.deb ... 224s Unpacking librust-async-executor-dev (1.13.1-1) ... 224s Selecting previously unselected package librust-async-lock-dev. 224s Preparing to unpack .../248-librust-async-lock-dev_3.4.0-4_all.deb ... 224s Unpacking librust-async-lock-dev (3.4.0-4) ... 225s Selecting previously unselected package librust-atomic-waker-dev:arm64. 225s Preparing to unpack .../249-librust-atomic-waker-dev_1.1.2-1_arm64.deb ... 225s Unpacking librust-atomic-waker-dev:arm64 (1.1.2-1) ... 225s Selecting previously unselected package librust-tracing-attributes-dev:arm64. 225s Preparing to unpack .../250-librust-tracing-attributes-dev_0.1.27-1_arm64.deb ... 225s Unpacking librust-tracing-attributes-dev:arm64 (0.1.27-1) ... 225s Selecting previously unselected package librust-valuable-derive-dev:arm64. 225s Preparing to unpack .../251-librust-valuable-derive-dev_0.1.0-1_arm64.deb ... 225s Unpacking librust-valuable-derive-dev:arm64 (0.1.0-1) ... 225s Selecting previously unselected package librust-valuable-dev:arm64. 225s Preparing to unpack .../252-librust-valuable-dev_0.1.0-4_arm64.deb ... 225s Unpacking librust-valuable-dev:arm64 (0.1.0-4) ... 225s Selecting previously unselected package librust-tracing-core-dev:arm64. 225s Preparing to unpack .../253-librust-tracing-core-dev_0.1.32-1_arm64.deb ... 225s Unpacking librust-tracing-core-dev:arm64 (0.1.32-1) ... 225s Selecting previously unselected package librust-tracing-dev:arm64. 225s Preparing to unpack .../254-librust-tracing-dev_0.1.40-1_arm64.deb ... 225s Unpacking librust-tracing-dev:arm64 (0.1.40-1) ... 225s Selecting previously unselected package librust-blocking-dev. 225s Preparing to unpack .../255-librust-blocking-dev_1.6.1-5_all.deb ... 225s Unpacking librust-blocking-dev (1.6.1-5) ... 225s Selecting previously unselected package librust-async-fs-dev. 225s Preparing to unpack .../256-librust-async-fs-dev_2.1.2-4_all.deb ... 225s Unpacking librust-async-fs-dev (2.1.2-4) ... 225s Selecting previously unselected package librust-bitflags-dev:arm64. 225s Preparing to unpack .../257-librust-bitflags-dev_2.6.0-1_arm64.deb ... 225s Unpacking librust-bitflags-dev:arm64 (2.6.0-1) ... 225s Selecting previously unselected package librust-compiler-builtins+core-dev:arm64. 225s Preparing to unpack .../258-librust-compiler-builtins+core-dev_0.1.101-1_arm64.deb ... 225s Unpacking librust-compiler-builtins+core-dev:arm64 (0.1.101-1) ... 225s Selecting previously unselected package librust-compiler-builtins+rustc-dep-of-std-dev:arm64. 225s Preparing to unpack .../259-librust-compiler-builtins+rustc-dep-of-std-dev_0.1.101-1_arm64.deb ... 225s Unpacking librust-compiler-builtins+rustc-dep-of-std-dev:arm64 (0.1.101-1) ... 225s Selecting previously unselected package librust-errno-dev:arm64. 225s Preparing to unpack .../260-librust-errno-dev_0.3.8-1_arm64.deb ... 225s Unpacking librust-errno-dev:arm64 (0.3.8-1) ... 225s Selecting previously unselected package librust-linux-raw-sys-dev:arm64. 225s Preparing to unpack .../261-librust-linux-raw-sys-dev_0.4.14-1_arm64.deb ... 225s Unpacking librust-linux-raw-sys-dev:arm64 (0.4.14-1) ... 225s Selecting previously unselected package librust-rustix-dev:arm64. 225s Preparing to unpack .../262-librust-rustix-dev_0.38.37-1_arm64.deb ... 225s Unpacking librust-rustix-dev:arm64 (0.38.37-1) ... 225s Selecting previously unselected package librust-polling-dev:arm64. 225s Preparing to unpack .../263-librust-polling-dev_3.4.0-1_arm64.deb ... 225s Unpacking librust-polling-dev:arm64 (3.4.0-1) ... 225s Selecting previously unselected package librust-async-io-dev:arm64. 225s Preparing to unpack .../264-librust-async-io-dev_2.3.3-4_arm64.deb ... 225s Unpacking librust-async-io-dev:arm64 (2.3.3-4) ... 225s Selecting previously unselected package librust-mio-dev:arm64. 225s Preparing to unpack .../265-librust-mio-dev_1.0.2-2_arm64.deb ... 225s Unpacking librust-mio-dev:arm64 (1.0.2-2) ... 225s Selecting previously unselected package librust-owning-ref-dev:arm64. 225s Preparing to unpack .../266-librust-owning-ref-dev_0.4.1-1_arm64.deb ... 225s Unpacking librust-owning-ref-dev:arm64 (0.4.1-1) ... 226s Selecting previously unselected package librust-scopeguard-dev:arm64. 226s Preparing to unpack .../267-librust-scopeguard-dev_1.2.0-1_arm64.deb ... 226s Unpacking librust-scopeguard-dev:arm64 (1.2.0-1) ... 226s Selecting previously unselected package librust-lock-api-dev:arm64. 226s Preparing to unpack .../268-librust-lock-api-dev_0.4.12-1_arm64.deb ... 226s Unpacking librust-lock-api-dev:arm64 (0.4.12-1) ... 226s Selecting previously unselected package librust-parking-lot-dev:arm64. 226s Preparing to unpack .../269-librust-parking-lot-dev_0.12.3-1_arm64.deb ... 226s Unpacking librust-parking-lot-dev:arm64 (0.12.3-1) ... 226s Selecting previously unselected package librust-signal-hook-registry-dev:arm64. 226s Preparing to unpack .../270-librust-signal-hook-registry-dev_1.4.0-1_arm64.deb ... 226s Unpacking librust-signal-hook-registry-dev:arm64 (1.4.0-1) ... 226s Selecting previously unselected package librust-socket2-dev:arm64. 226s Preparing to unpack .../271-librust-socket2-dev_0.5.7-1_arm64.deb ... 226s Unpacking librust-socket2-dev:arm64 (0.5.7-1) ... 226s Selecting previously unselected package librust-tokio-macros-dev:arm64. 226s Preparing to unpack .../272-librust-tokio-macros-dev_2.4.0-2_arm64.deb ... 226s Unpacking librust-tokio-macros-dev:arm64 (2.4.0-2) ... 226s Selecting previously unselected package librust-tokio-dev:arm64. 226s Preparing to unpack .../273-librust-tokio-dev_1.39.3-3_arm64.deb ... 226s Unpacking librust-tokio-dev:arm64 (1.39.3-3) ... 226s Selecting previously unselected package librust-async-global-executor-dev:arm64. 226s Preparing to unpack .../274-librust-async-global-executor-dev_2.4.1-5_arm64.deb ... 226s Unpacking librust-async-global-executor-dev:arm64 (2.4.1-5) ... 226s Selecting previously unselected package librust-async-net-dev. 226s Preparing to unpack .../275-librust-async-net-dev_2.0.0-4_all.deb ... 226s Unpacking librust-async-net-dev (2.0.0-4) ... 226s Selecting previously unselected package librust-async-signal-dev:arm64. 226s Preparing to unpack .../276-librust-async-signal-dev_0.2.10-1_arm64.deb ... 226s Unpacking librust-async-signal-dev:arm64 (0.2.10-1) ... 226s Selecting previously unselected package librust-async-process-dev. 226s Preparing to unpack .../277-librust-async-process-dev_2.3.0-1_all.deb ... 226s Unpacking librust-async-process-dev (2.3.0-1) ... 226s Selecting previously unselected package librust-kv-log-macro-dev. 226s Preparing to unpack .../278-librust-kv-log-macro-dev_1.0.8-4_all.deb ... 226s Unpacking librust-kv-log-macro-dev (1.0.8-4) ... 226s Selecting previously unselected package librust-pin-utils-dev:arm64. 226s Preparing to unpack .../279-librust-pin-utils-dev_0.1.0-1_arm64.deb ... 226s Unpacking librust-pin-utils-dev:arm64 (0.1.0-1) ... 226s Selecting previously unselected package librust-async-std-dev. 226s Preparing to unpack .../280-librust-async-std-dev_1.13.0-1_all.deb ... 226s Unpacking librust-async-std-dev (1.13.0-1) ... 226s Selecting previously unselected package librust-base64-dev:arm64. 226s Preparing to unpack .../281-librust-base64-dev_0.21.7-1_arm64.deb ... 226s Unpacking librust-base64-dev:arm64 (0.21.7-1) ... 226s Selecting previously unselected package librust-bit-vec-dev:arm64. 226s Preparing to unpack .../282-librust-bit-vec-dev_0.6.3-1_arm64.deb ... 226s Unpacking librust-bit-vec-dev:arm64 (0.6.3-1) ... 226s Selecting previously unselected package librust-bit-set-dev:arm64. 226s Preparing to unpack .../283-librust-bit-set-dev_0.5.2-1_arm64.deb ... 226s Unpacking librust-bit-set-dev:arm64 (0.5.2-1) ... 226s Selecting previously unselected package librust-bit-set+std-dev:arm64. 226s Preparing to unpack .../284-librust-bit-set+std-dev_0.5.2-1_arm64.deb ... 226s Unpacking librust-bit-set+std-dev:arm64 (0.5.2-1) ... 226s Selecting previously unselected package librust-regex-syntax-dev:arm64. 226s Preparing to unpack .../285-librust-regex-syntax-dev_0.8.5-1_arm64.deb ... 226s Unpacking librust-regex-syntax-dev:arm64 (0.8.5-1) ... 227s Selecting previously unselected package librust-regex-automata-dev:arm64. 227s Preparing to unpack .../286-librust-regex-automata-dev_0.4.9-1_arm64.deb ... 227s Unpacking librust-regex-automata-dev:arm64 (0.4.9-1) ... 227s Selecting previously unselected package librust-bstr-dev:arm64. 227s Preparing to unpack .../287-librust-bstr-dev_1.7.0-2build1_arm64.deb ... 227s Unpacking librust-bstr-dev:arm64 (1.7.0-2build1) ... 227s Selecting previously unselected package librust-bumpalo-dev:arm64. 227s Preparing to unpack .../288-librust-bumpalo-dev_3.16.0-1_arm64.deb ... 227s Unpacking librust-bumpalo-dev:arm64 (3.16.0-1) ... 227s Selecting previously unselected package librust-cast-dev:arm64. 227s Preparing to unpack .../289-librust-cast-dev_0.3.0-1_arm64.deb ... 227s Unpacking librust-cast-dev:arm64 (0.3.0-1) ... 227s Selecting previously unselected package librust-iana-time-zone-dev:arm64. 227s Preparing to unpack .../290-librust-iana-time-zone-dev_0.1.60-1_arm64.deb ... 227s Unpacking librust-iana-time-zone-dev:arm64 (0.1.60-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-shared-dev:arm64. 227s Preparing to unpack .../291-librust-wasm-bindgen-shared-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-shared-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-backend-dev:arm64. 227s Preparing to unpack .../292-librust-wasm-bindgen-backend-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-backend-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-macro-support-dev:arm64. 227s Preparing to unpack .../293-librust-wasm-bindgen-macro-support-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-macro-support-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-macro-dev:arm64. 227s Preparing to unpack .../294-librust-wasm-bindgen-macro-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-macro-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-dev:arm64. 227s Preparing to unpack .../295-librust-wasm-bindgen-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-macro-support+spans-dev:arm64. 227s Preparing to unpack .../296-librust-wasm-bindgen-macro-support+spans-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-macro-support+spans-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen-macro+spans-dev:arm64. 227s Preparing to unpack .../297-librust-wasm-bindgen-macro+spans-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen-macro+spans-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen+spans-dev:arm64. 227s Preparing to unpack .../298-librust-wasm-bindgen+spans-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen+spans-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-wasm-bindgen+default-dev:arm64. 227s Preparing to unpack .../299-librust-wasm-bindgen+default-dev_0.2.87-1_arm64.deb ... 227s Unpacking librust-wasm-bindgen+default-dev:arm64 (0.2.87-1) ... 227s Selecting previously unselected package librust-js-sys-dev:arm64. 227s Preparing to unpack .../300-librust-js-sys-dev_0.3.64-1_arm64.deb ... 227s Unpacking librust-js-sys-dev:arm64 (0.3.64-1) ... 227s Selecting previously unselected package librust-pure-rust-locales-dev:arm64. 227s Preparing to unpack .../301-librust-pure-rust-locales-dev_0.8.1-1_arm64.deb ... 227s Unpacking librust-pure-rust-locales-dev:arm64 (0.8.1-1) ... 227s Selecting previously unselected package librust-chrono-dev:arm64. 227s Preparing to unpack .../302-librust-chrono-dev_0.4.38-2_arm64.deb ... 227s Unpacking librust-chrono-dev:arm64 (0.4.38-2) ... 227s Selecting previously unselected package librust-regex-dev:arm64. 227s Preparing to unpack .../303-librust-regex-dev_1.10.6-1_arm64.deb ... 227s Unpacking librust-regex-dev:arm64 (1.10.6-1) ... 228s Selecting previously unselected package librust-parse-zoneinfo-dev:arm64. 228s Preparing to unpack .../304-librust-parse-zoneinfo-dev_0.3.0-1_arm64.deb ... 228s Unpacking librust-parse-zoneinfo-dev:arm64 (0.3.0-1) ... 228s Selecting previously unselected package librust-siphasher-dev:arm64. 228s Preparing to unpack .../305-librust-siphasher-dev_0.3.10-1_arm64.deb ... 228s Unpacking librust-siphasher-dev:arm64 (0.3.10-1) ... 228s Selecting previously unselected package librust-phf-shared-dev:arm64. 228s Preparing to unpack .../306-librust-phf-shared-dev_0.11.2-1_arm64.deb ... 228s Unpacking librust-phf-shared-dev:arm64 (0.11.2-1) ... 228s Selecting previously unselected package librust-phf-dev:arm64. 228s Preparing to unpack .../307-librust-phf-dev_0.11.2-1_arm64.deb ... 228s Unpacking librust-phf-dev:arm64 (0.11.2-1) ... 228s Selecting previously unselected package librust-uncased-dev:arm64. 228s Preparing to unpack .../308-librust-uncased-dev_0.9.6-2_arm64.deb ... 228s Unpacking librust-uncased-dev:arm64 (0.9.6-2) ... 228s Selecting previously unselected package librust-phf-shared+uncased-dev:arm64. 228s Preparing to unpack .../309-librust-phf-shared+uncased-dev_0.11.2-1_arm64.deb ... 228s Unpacking librust-phf-shared+uncased-dev:arm64 (0.11.2-1) ... 228s Selecting previously unselected package librust-phf+uncased-dev:arm64. 228s Preparing to unpack .../310-librust-phf+uncased-dev_0.11.2-1_arm64.deb ... 228s Unpacking librust-phf+uncased-dev:arm64 (0.11.2-1) ... 228s Selecting previously unselected package librust-ciborium-io-dev:arm64. 228s Preparing to unpack .../311-librust-ciborium-io-dev_0.2.2-1_arm64.deb ... 228s Unpacking librust-ciborium-io-dev:arm64 (0.2.2-1) ... 228s Selecting previously unselected package librust-half-dev:arm64. 228s Preparing to unpack .../312-librust-half-dev_1.8.2-4_arm64.deb ... 228s Unpacking librust-half-dev:arm64 (1.8.2-4) ... 228s Selecting previously unselected package librust-ciborium-ll-dev:arm64. 228s Preparing to unpack .../313-librust-ciborium-ll-dev_0.2.2-1_arm64.deb ... 228s Unpacking librust-ciborium-ll-dev:arm64 (0.2.2-1) ... 228s Selecting previously unselected package librust-ciborium-dev:arm64. 228s Preparing to unpack .../314-librust-ciborium-dev_0.2.2-2_arm64.deb ... 228s Unpacking librust-ciborium-dev:arm64 (0.2.2-2) ... 228s Selecting previously unselected package librust-clap-lex-dev:arm64. 228s Preparing to unpack .../315-librust-clap-lex-dev_0.7.2-2_arm64.deb ... 228s Unpacking librust-clap-lex-dev:arm64 (0.7.2-2) ... 228s Selecting previously unselected package librust-strsim-dev:arm64. 228s Preparing to unpack .../316-librust-strsim-dev_0.11.1-1_arm64.deb ... 228s Unpacking librust-strsim-dev:arm64 (0.11.1-1) ... 228s Selecting previously unselected package librust-terminal-size-dev:arm64. 228s Preparing to unpack .../317-librust-terminal-size-dev_0.3.0-2_arm64.deb ... 228s Unpacking librust-terminal-size-dev:arm64 (0.3.0-2) ... 228s Selecting previously unselected package librust-unicase-dev:arm64. 228s Preparing to unpack .../318-librust-unicase-dev_2.7.0-1_arm64.deb ... 228s Unpacking librust-unicase-dev:arm64 (2.7.0-1) ... 228s Selecting previously unselected package librust-unicode-width-dev:arm64. 228s Preparing to unpack .../319-librust-unicode-width-dev_0.1.14-1_arm64.deb ... 228s Unpacking librust-unicode-width-dev:arm64 (0.1.14-1) ... 228s Selecting previously unselected package librust-clap-builder-dev:arm64. 228s Preparing to unpack .../320-librust-clap-builder-dev_4.5.15-2_arm64.deb ... 228s Unpacking librust-clap-builder-dev:arm64 (4.5.15-2) ... 228s Selecting previously unselected package librust-heck-dev:arm64. 228s Preparing to unpack .../321-librust-heck-dev_0.4.1-1_arm64.deb ... 228s Unpacking librust-heck-dev:arm64 (0.4.1-1) ... 228s Selecting previously unselected package librust-clap-derive-dev:arm64. 229s Preparing to unpack .../322-librust-clap-derive-dev_4.5.13-2_arm64.deb ... 229s Unpacking librust-clap-derive-dev:arm64 (4.5.13-2) ... 229s Selecting previously unselected package librust-clap-dev:arm64. 229s Preparing to unpack .../323-librust-clap-dev_4.5.16-1_arm64.deb ... 229s Unpacking librust-clap-dev:arm64 (4.5.16-1) ... 229s Selecting previously unselected package librust-csv-core-dev:arm64. 229s Preparing to unpack .../324-librust-csv-core-dev_0.1.11-1_arm64.deb ... 229s Unpacking librust-csv-core-dev:arm64 (0.1.11-1) ... 229s Selecting previously unselected package librust-csv-dev:arm64. 229s Preparing to unpack .../325-librust-csv-dev_1.3.0-1_arm64.deb ... 229s Unpacking librust-csv-dev:arm64 (1.3.0-1) ... 229s Selecting previously unselected package librust-futures-sink-dev:arm64. 229s Preparing to unpack .../326-librust-futures-sink-dev_0.3.31-1_arm64.deb ... 229s Unpacking librust-futures-sink-dev:arm64 (0.3.31-1) ... 229s Selecting previously unselected package librust-futures-channel-dev:arm64. 229s Preparing to unpack .../327-librust-futures-channel-dev_0.3.30-1_arm64.deb ... 229s Unpacking librust-futures-channel-dev:arm64 (0.3.30-1) ... 229s Selecting previously unselected package librust-futures-task-dev:arm64. 229s Preparing to unpack .../328-librust-futures-task-dev_0.3.30-1_arm64.deb ... 229s Unpacking librust-futures-task-dev:arm64 (0.3.30-1) ... 229s Selecting previously unselected package librust-futures-macro-dev:arm64. 229s Preparing to unpack .../329-librust-futures-macro-dev_0.3.30-1_arm64.deb ... 229s Unpacking librust-futures-macro-dev:arm64 (0.3.30-1) ... 229s Selecting previously unselected package librust-futures-util-dev:arm64. 229s Preparing to unpack .../330-librust-futures-util-dev_0.3.30-2_arm64.deb ... 229s Unpacking librust-futures-util-dev:arm64 (0.3.30-2) ... 229s Selecting previously unselected package librust-num-cpus-dev:arm64. 229s Preparing to unpack .../331-librust-num-cpus-dev_1.16.0-1_arm64.deb ... 229s Unpacking librust-num-cpus-dev:arm64 (1.16.0-1) ... 229s Selecting previously unselected package librust-futures-executor-dev:arm64. 229s Preparing to unpack .../332-librust-futures-executor-dev_0.3.30-1_arm64.deb ... 229s Unpacking librust-futures-executor-dev:arm64 (0.3.30-1) ... 229s Selecting previously unselected package librust-futures-dev:arm64. 229s Preparing to unpack .../333-librust-futures-dev_0.3.30-2_arm64.deb ... 229s Unpacking librust-futures-dev:arm64 (0.3.30-2) ... 229s Selecting previously unselected package librust-is-terminal-dev:arm64. 229s Preparing to unpack .../334-librust-is-terminal-dev_0.4.13-1_arm64.deb ... 229s Unpacking librust-is-terminal-dev:arm64 (0.4.13-1) ... 229s Selecting previously unselected package librust-itertools-dev:arm64. 229s Preparing to unpack .../335-librust-itertools-dev_0.10.5-1_arm64.deb ... 229s Unpacking librust-itertools-dev:arm64 (0.10.5-1) ... 229s Selecting previously unselected package librust-oorandom-dev:arm64. 229s Preparing to unpack .../336-librust-oorandom-dev_11.1.3-1_arm64.deb ... 229s Unpacking librust-oorandom-dev:arm64 (11.1.3-1) ... 229s Selecting previously unselected package librust-winapi-i686-pc-windows-gnu-dev:arm64. 229s Preparing to unpack .../337-librust-winapi-i686-pc-windows-gnu-dev_0.4.0-1_arm64.deb ... 229s Unpacking librust-winapi-i686-pc-windows-gnu-dev:arm64 (0.4.0-1) ... 229s Selecting previously unselected package librust-winapi-x86-64-pc-windows-gnu-dev:arm64. 229s Preparing to unpack .../338-librust-winapi-x86-64-pc-windows-gnu-dev_0.4.0-1_arm64.deb ... 229s Unpacking librust-winapi-x86-64-pc-windows-gnu-dev:arm64 (0.4.0-1) ... 229s Selecting previously unselected package librust-winapi-dev:arm64. 230s Preparing to unpack .../339-librust-winapi-dev_0.3.9-1_arm64.deb ... 230s Unpacking librust-winapi-dev:arm64 (0.3.9-1) ... 230s Selecting previously unselected package librust-dirs-sys-next-dev:arm64. 230s Preparing to unpack .../340-librust-dirs-sys-next-dev_0.1.1-1_arm64.deb ... 230s Unpacking librust-dirs-sys-next-dev:arm64 (0.1.1-1) ... 230s Selecting previously unselected package librust-dirs-next-dev:arm64. 230s Preparing to unpack .../341-librust-dirs-next-dev_2.0.0-1_arm64.deb ... 230s Unpacking librust-dirs-next-dev:arm64 (2.0.0-1) ... 230s Selecting previously unselected package librust-float-ord-dev:arm64. 230s Preparing to unpack .../342-librust-float-ord-dev_0.3.2-1_arm64.deb ... 230s Unpacking librust-float-ord-dev:arm64 (0.3.2-1) ... 230s Selecting previously unselected package librust-cmake-dev:arm64. 230s Preparing to unpack .../343-librust-cmake-dev_0.1.45-1_arm64.deb ... 230s Unpacking librust-cmake-dev:arm64 (0.1.45-1) ... 230s Selecting previously unselected package librust-freetype-sys-dev:arm64. 230s Preparing to unpack .../344-librust-freetype-sys-dev_0.13.1-1_arm64.deb ... 230s Unpacking librust-freetype-sys-dev:arm64 (0.13.1-1) ... 230s Selecting previously unselected package librust-freetype-dev:arm64. 230s Preparing to unpack .../345-librust-freetype-dev_0.7.0-4_arm64.deb ... 230s Unpacking librust-freetype-dev:arm64 (0.7.0-4) ... 230s Selecting previously unselected package librust-spin-dev:arm64. 230s Preparing to unpack .../346-librust-spin-dev_0.9.8-4_arm64.deb ... 230s Unpacking librust-spin-dev:arm64 (0.9.8-4) ... 230s Selecting previously unselected package librust-lazy-static-dev:arm64. 230s Preparing to unpack .../347-librust-lazy-static-dev_1.5.0-1_arm64.deb ... 230s Unpacking librust-lazy-static-dev:arm64 (1.5.0-1) ... 230s Selecting previously unselected package librust-pathfinder-simd-dev:arm64. 230s Preparing to unpack .../348-librust-pathfinder-simd-dev_0.5.2-1_arm64.deb ... 230s Unpacking librust-pathfinder-simd-dev:arm64 (0.5.2-1) ... 230s Selecting previously unselected package librust-pathfinder-geometry-dev:arm64. 230s Preparing to unpack .../349-librust-pathfinder-geometry-dev_0.5.1-1_arm64.deb ... 230s Unpacking librust-pathfinder-geometry-dev:arm64 (0.5.1-1) ... 230s Selecting previously unselected package librust-winapi-util-dev:arm64. 230s Preparing to unpack .../350-librust-winapi-util-dev_0.1.6-1_arm64.deb ... 230s Unpacking librust-winapi-util-dev:arm64 (0.1.6-1) ... 230s Selecting previously unselected package librust-same-file-dev:arm64. 230s Preparing to unpack .../351-librust-same-file-dev_1.0.6-1_arm64.deb ... 230s Unpacking librust-same-file-dev:arm64 (1.0.6-1) ... 230s Selecting previously unselected package librust-walkdir-dev:arm64. 230s Preparing to unpack .../352-librust-walkdir-dev_2.5.0-1_arm64.deb ... 230s Unpacking librust-walkdir-dev:arm64 (2.5.0-1) ... 230s Selecting previously unselected package librust-const-cstr-dev:arm64. 230s Preparing to unpack .../353-librust-const-cstr-dev_0.3.0-1_arm64.deb ... 230s Unpacking librust-const-cstr-dev:arm64 (0.3.0-1) ... 230s Selecting previously unselected package librust-libloading-dev:arm64. 230s Preparing to unpack .../354-librust-libloading-dev_0.8.5-1_arm64.deb ... 230s Unpacking librust-libloading-dev:arm64 (0.8.5-1) ... 230s Selecting previously unselected package librust-dlib-dev:arm64. 231s Preparing to unpack .../355-librust-dlib-dev_0.5.2-2_arm64.deb ... 231s Unpacking librust-dlib-dev:arm64 (0.5.2-2) ... 231s Selecting previously unselected package librust-yeslogic-fontconfig-sys-dev:arm64. 231s Preparing to unpack .../356-librust-yeslogic-fontconfig-sys-dev_3.0.1-1_arm64.deb ... 231s Unpacking librust-yeslogic-fontconfig-sys-dev:arm64 (3.0.1-1) ... 231s Selecting previously unselected package librust-font-kit-dev:arm64. 231s Preparing to unpack .../357-librust-font-kit-dev_0.11.0-2_arm64.deb ... 231s Unpacking librust-font-kit-dev:arm64 (0.11.0-2) ... 231s Selecting previously unselected package librust-color-quant-dev:arm64. 231s Preparing to unpack .../358-librust-color-quant-dev_1.1.0-1_arm64.deb ... 231s Unpacking librust-color-quant-dev:arm64 (1.1.0-1) ... 231s Selecting previously unselected package librust-weezl-dev:arm64. 231s Preparing to unpack .../359-librust-weezl-dev_0.1.5-1_arm64.deb ... 231s Unpacking librust-weezl-dev:arm64 (0.1.5-1) ... 231s Selecting previously unselected package librust-gif-dev:arm64. 231s Preparing to unpack .../360-librust-gif-dev_0.11.3-1_arm64.deb ... 231s Unpacking librust-gif-dev:arm64 (0.11.3-1) ... 231s Selecting previously unselected package librust-jpeg-decoder-dev:arm64. 231s Preparing to unpack .../361-librust-jpeg-decoder-dev_0.3.0-1_arm64.deb ... 231s Unpacking librust-jpeg-decoder-dev:arm64 (0.3.0-1) ... 231s Selecting previously unselected package librust-num-integer-dev:arm64. 231s Preparing to unpack .../362-librust-num-integer-dev_0.1.46-1_arm64.deb ... 231s Unpacking librust-num-integer-dev:arm64 (0.1.46-1) ... 231s Selecting previously unselected package librust-humantime-dev:arm64. 231s Preparing to unpack .../363-librust-humantime-dev_2.1.0-1_arm64.deb ... 231s Unpacking librust-humantime-dev:arm64 (2.1.0-1) ... 231s Selecting previously unselected package librust-termcolor-dev:arm64. 231s Preparing to unpack .../364-librust-termcolor-dev_1.4.1-1_arm64.deb ... 231s Unpacking librust-termcolor-dev:arm64 (1.4.1-1) ... 231s Selecting previously unselected package librust-env-logger-dev:arm64. 231s Preparing to unpack .../365-librust-env-logger-dev_0.10.2-2_arm64.deb ... 231s Unpacking librust-env-logger-dev:arm64 (0.10.2-2) ... 231s Selecting previously unselected package librust-quickcheck-dev:arm64. 231s Preparing to unpack .../366-librust-quickcheck-dev_1.0.3-3_arm64.deb ... 231s Unpacking librust-quickcheck-dev:arm64 (1.0.3-3) ... 231s Selecting previously unselected package librust-num-bigint-dev:arm64. 231s Preparing to unpack .../367-librust-num-bigint-dev_0.4.6-1_arm64.deb ... 231s Unpacking librust-num-bigint-dev:arm64 (0.4.6-1) ... 231s Selecting previously unselected package librust-num-rational-dev:arm64. 231s Preparing to unpack .../368-librust-num-rational-dev_0.4.2-1_arm64.deb ... 231s Unpacking librust-num-rational-dev:arm64 (0.4.2-1) ... 231s Selecting previously unselected package librust-png-dev:arm64. 231s Preparing to unpack .../369-librust-png-dev_0.17.7-3_arm64.deb ... 231s Unpacking librust-png-dev:arm64 (0.17.7-3) ... 231s Selecting previously unselected package librust-qoi-dev:arm64. 231s Preparing to unpack .../370-librust-qoi-dev_0.4.1-2_arm64.deb ... 231s Unpacking librust-qoi-dev:arm64 (0.4.1-2) ... 231s Selecting previously unselected package librust-tiff-dev:arm64. 231s Preparing to unpack .../371-librust-tiff-dev_0.9.0-1_arm64.deb ... 231s Unpacking librust-tiff-dev:arm64 (0.9.0-1) ... 232s Selecting previously unselected package libsharpyuv0:arm64. 232s Preparing to unpack .../372-libsharpyuv0_1.4.0-0.1_arm64.deb ... 232s Unpacking libsharpyuv0:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libwebp7:arm64. 232s Preparing to unpack .../373-libwebp7_1.4.0-0.1_arm64.deb ... 232s Unpacking libwebp7:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libwebpdemux2:arm64. 232s Preparing to unpack .../374-libwebpdemux2_1.4.0-0.1_arm64.deb ... 232s Unpacking libwebpdemux2:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libwebpmux3:arm64. 232s Preparing to unpack .../375-libwebpmux3_1.4.0-0.1_arm64.deb ... 232s Unpacking libwebpmux3:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libwebpdecoder3:arm64. 232s Preparing to unpack .../376-libwebpdecoder3_1.4.0-0.1_arm64.deb ... 232s Unpacking libwebpdecoder3:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libsharpyuv-dev:arm64. 232s Preparing to unpack .../377-libsharpyuv-dev_1.4.0-0.1_arm64.deb ... 232s Unpacking libsharpyuv-dev:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package libwebp-dev:arm64. 232s Preparing to unpack .../378-libwebp-dev_1.4.0-0.1_arm64.deb ... 232s Unpacking libwebp-dev:arm64 (1.4.0-0.1) ... 232s Selecting previously unselected package librust-libwebp-sys-dev:arm64. 232s Preparing to unpack .../379-librust-libwebp-sys-dev_0.9.5-1build1_arm64.deb ... 232s Unpacking librust-libwebp-sys-dev:arm64 (0.9.5-1build1) ... 232s Selecting previously unselected package librust-webp-dev:arm64. 232s Preparing to unpack .../380-librust-webp-dev_0.2.6-1_arm64.deb ... 232s Unpacking librust-webp-dev:arm64 (0.2.6-1) ... 232s Selecting previously unselected package librust-image-dev:arm64. 232s Preparing to unpack .../381-librust-image-dev_0.24.7-2_arm64.deb ... 232s Unpacking librust-image-dev:arm64 (0.24.7-2) ... 232s Selecting previously unselected package librust-plotters-backend-dev:arm64. 232s Preparing to unpack .../382-librust-plotters-backend-dev_0.3.7-1_arm64.deb ... 232s Unpacking librust-plotters-backend-dev:arm64 (0.3.7-1) ... 232s Selecting previously unselected package librust-plotters-bitmap-dev:arm64. 232s Preparing to unpack .../383-librust-plotters-bitmap-dev_0.3.3-3_arm64.deb ... 232s Unpacking librust-plotters-bitmap-dev:arm64 (0.3.3-3) ... 232s Selecting previously unselected package librust-plotters-svg-dev:arm64. 232s Preparing to unpack .../384-librust-plotters-svg-dev_0.3.5-1_arm64.deb ... 232s Unpacking librust-plotters-svg-dev:arm64 (0.3.5-1) ... 232s Selecting previously unselected package librust-web-sys-dev:arm64. 232s Preparing to unpack .../385-librust-web-sys-dev_0.3.64-2_arm64.deb ... 232s Unpacking librust-web-sys-dev:arm64 (0.3.64-2) ... 233s Selecting previously unselected package librust-plotters-dev:arm64. 233s Preparing to unpack .../386-librust-plotters-dev_0.3.5-4_arm64.deb ... 233s Unpacking librust-plotters-dev:arm64 (0.3.5-4) ... 233s Selecting previously unselected package librust-smol-dev. 233s Preparing to unpack .../387-librust-smol-dev_2.0.2-1_all.deb ... 233s Unpacking librust-smol-dev (2.0.2-1) ... 233s Selecting previously unselected package librust-tinytemplate-dev:arm64. 233s Preparing to unpack .../388-librust-tinytemplate-dev_1.2.1-1_arm64.deb ... 233s Unpacking librust-tinytemplate-dev:arm64 (1.2.1-1) ... 233s Selecting previously unselected package librust-criterion-dev. 233s Preparing to unpack .../389-librust-criterion-dev_0.5.1-6_all.deb ... 233s Unpacking librust-criterion-dev (0.5.1-6) ... 233s Selecting previously unselected package librust-phf-generator-dev:arm64. 233s Preparing to unpack .../390-librust-phf-generator-dev_0.11.2-2_arm64.deb ... 233s Unpacking librust-phf-generator-dev:arm64 (0.11.2-2) ... 233s Selecting previously unselected package librust-phf-codegen-dev:arm64. 233s Preparing to unpack .../391-librust-phf-codegen-dev_0.11.2-1_arm64.deb ... 233s Unpacking librust-phf-codegen-dev:arm64 (0.11.2-1) ... 233s Selecting previously unselected package librust-chrono-tz-build-dev:arm64. 233s Preparing to unpack .../392-librust-chrono-tz-build-dev_0.2.1-1_arm64.deb ... 233s Unpacking librust-chrono-tz-build-dev:arm64 (0.2.1-1) ... 233s Selecting previously unselected package librust-chrono-tz-dev:arm64. 233s Preparing to unpack .../393-librust-chrono-tz-dev_0.8.6-2_arm64.deb ... 233s Unpacking librust-chrono-tz-dev:arm64 (0.8.6-2) ... 233s Selecting previously unselected package librust-ctor-dev:arm64. 233s Preparing to unpack .../394-librust-ctor-dev_0.1.26-1_arm64.deb ... 233s Unpacking librust-ctor-dev:arm64 (0.1.26-1) ... 233s Selecting previously unselected package librust-powerfmt-macros-dev:arm64. 233s Preparing to unpack .../395-librust-powerfmt-macros-dev_0.1.0-1_arm64.deb ... 233s Unpacking librust-powerfmt-macros-dev:arm64 (0.1.0-1) ... 233s Selecting previously unselected package librust-powerfmt-dev:arm64. 233s Preparing to unpack .../396-librust-powerfmt-dev_0.2.0-1_arm64.deb ... 233s Unpacking librust-powerfmt-dev:arm64 (0.2.0-1) ... 233s Selecting previously unselected package librust-deranged-dev:arm64. 233s Preparing to unpack .../397-librust-deranged-dev_0.3.11-1_arm64.deb ... 233s Unpacking librust-deranged-dev:arm64 (0.3.11-1) ... 233s Selecting previously unselected package librust-eui48-dev:arm64. 233s Preparing to unpack .../398-librust-eui48-dev_1.1.0-2_arm64.deb ... 233s Unpacking librust-eui48-dev:arm64 (1.1.0-2) ... 233s Selecting previously unselected package librust-indenter-dev:arm64. 233s Preparing to unpack .../399-librust-indenter-dev_0.3.3-1_arm64.deb ... 233s Unpacking librust-indenter-dev:arm64 (0.3.3-1) ... 233s Selecting previously unselected package librust-eyre-dev:arm64. 233s Preparing to unpack .../400-librust-eyre-dev_0.6.12-1_arm64.deb ... 233s Unpacking librust-eyre-dev:arm64 (0.6.12-1) ... 234s Selecting previously unselected package librust-eyre+default-dev:arm64. 234s Preparing to unpack .../401-librust-eyre+default-dev_0.6.12-1_arm64.deb ... 234s Unpacking librust-eyre+default-dev:arm64 (0.6.12-1) ... 234s Selecting previously unselected package librust-fancy-regex-dev:arm64. 234s Preparing to unpack .../402-librust-fancy-regex-dev_0.11.0-2_arm64.deb ... 234s Unpacking librust-fancy-regex-dev:arm64 (0.11.0-2) ... 234s Selecting previously unselected package librust-fnv-dev:arm64. 234s Preparing to unpack .../403-librust-fnv-dev_1.0.7-1_arm64.deb ... 234s Unpacking librust-fnv-dev:arm64 (1.0.7-1) ... 234s Selecting previously unselected package librust-geo-types-dev:arm64. 234s Preparing to unpack .../404-librust-geo-types-dev_0.7.11-2_arm64.deb ... 234s Unpacking librust-geo-types-dev:arm64 (0.7.11-2) ... 234s Selecting previously unselected package librust-ghost-dev:arm64. 234s Preparing to unpack .../405-librust-ghost-dev_0.1.5-1_arm64.deb ... 234s Unpacking librust-ghost-dev:arm64 (0.1.5-1) ... 234s Selecting previously unselected package librust-hmac-dev:arm64. 234s Preparing to unpack .../406-librust-hmac-dev_0.12.1-1_arm64.deb ... 234s Unpacking librust-hmac-dev:arm64 (0.12.1-1) ... 234s Selecting previously unselected package librust-indoc-dev:arm64. 234s Preparing to unpack .../407-librust-indoc-dev_2.0.5-1_arm64.deb ... 234s Unpacking librust-indoc-dev:arm64 (2.0.5-1) ... 234s Selecting previously unselected package librust-inventory-dev:arm64. 234s Preparing to unpack .../408-librust-inventory-dev_0.3.2-1_arm64.deb ... 234s Unpacking librust-inventory-dev:arm64 (0.3.2-1) ... 234s Selecting previously unselected package librust-memoffset-dev:arm64. 234s Preparing to unpack .../409-librust-memoffset-dev_0.8.0-1_arm64.deb ... 234s Unpacking librust-memoffset-dev:arm64 (0.8.0-1) ... 234s Selecting previously unselected package librust-num-conv-dev:arm64. 234s Preparing to unpack .../410-librust-num-conv-dev_0.1.0-1_arm64.deb ... 234s Unpacking librust-num-conv-dev:arm64 (0.1.0-1) ... 234s Selecting previously unselected package librust-num-threads-dev:arm64. 234s Preparing to unpack .../411-librust-num-threads-dev_0.1.7-1_arm64.deb ... 234s Unpacking librust-num-threads-dev:arm64 (0.1.7-1) ... 234s Selecting previously unselected package librust-postgres-derive-dev:arm64. 234s Preparing to unpack .../412-librust-postgres-derive-dev_0.4.5-1_arm64.deb ... 234s Unpacking librust-postgres-derive-dev:arm64 (0.4.5-1) ... 234s Selecting previously unselected package librust-sha2-asm-dev:arm64. 234s Preparing to unpack .../413-librust-sha2-asm-dev_0.6.2-2_arm64.deb ... 234s Unpacking librust-sha2-asm-dev:arm64 (0.6.2-2) ... 234s Selecting previously unselected package librust-sha2-dev:arm64. 234s Preparing to unpack .../414-librust-sha2-dev_0.10.8-1_arm64.deb ... 234s Unpacking librust-sha2-dev:arm64 (0.10.8-1) ... 234s Selecting previously unselected package librust-unicode-bidi-dev:arm64. 234s Preparing to unpack .../415-librust-unicode-bidi-dev_0.3.13-1_arm64.deb ... 234s Unpacking librust-unicode-bidi-dev:arm64 (0.3.13-1) ... 234s Selecting previously unselected package librust-unicode-normalization-dev:arm64. 234s Preparing to unpack .../416-librust-unicode-normalization-dev_0.1.22-1_arm64.deb ... 234s Unpacking librust-unicode-normalization-dev:arm64 (0.1.22-1) ... 234s Selecting previously unselected package librust-stringprep-dev:arm64. 234s Preparing to unpack .../417-librust-stringprep-dev_0.1.2-1_arm64.deb ... 234s Unpacking librust-stringprep-dev:arm64 (0.1.2-1) ... 235s Selecting previously unselected package librust-postgres-protocol-dev:arm64. 235s Preparing to unpack .../418-librust-postgres-protocol-dev_0.6.6-2_arm64.deb ... 235s Unpacking librust-postgres-protocol-dev:arm64 (0.6.6-2) ... 235s Selecting previously unselected package librust-time-core-dev:arm64. 235s Preparing to unpack .../419-librust-time-core-dev_0.1.2-1_arm64.deb ... 235s Unpacking librust-time-core-dev:arm64 (0.1.2-1) ... 235s Selecting previously unselected package librust-time-macros-dev:arm64. 235s Preparing to unpack .../420-librust-time-macros-dev_0.2.16-1_arm64.deb ... 235s Unpacking librust-time-macros-dev:arm64 (0.2.16-1) ... 235s Selecting previously unselected package librust-time-dev:arm64. 235s Preparing to unpack .../421-librust-time-dev_0.3.36-2_arm64.deb ... 235s Unpacking librust-time-dev:arm64 (0.3.36-2) ... 235s Selecting previously unselected package librust-postgres-types-dev:arm64. 235s Preparing to unpack .../422-librust-postgres-types-dev_0.2.6-2_arm64.deb ... 235s Unpacking librust-postgres-types-dev:arm64 (0.2.6-2) ... 235s Selecting previously unselected package librust-rand-xorshift-dev:arm64. 235s Preparing to unpack .../423-librust-rand-xorshift-dev_0.3.0-2_arm64.deb ... 235s Unpacking librust-rand-xorshift-dev:arm64 (0.3.0-2) ... 235s Selecting previously unselected package librust-quick-error-dev:arm64. 235s Preparing to unpack .../424-librust-quick-error-dev_2.0.1-1_arm64.deb ... 235s Unpacking librust-quick-error-dev:arm64 (2.0.1-1) ... 235s Selecting previously unselected package librust-tempfile-dev:arm64. 235s Preparing to unpack .../425-librust-tempfile-dev_3.13.0-1_arm64.deb ... 235s Unpacking librust-tempfile-dev:arm64 (3.13.0-1) ... 235s Selecting previously unselected package librust-rusty-fork-dev:arm64. 235s Preparing to unpack .../426-librust-rusty-fork-dev_0.3.0-1_arm64.deb ... 235s Unpacking librust-rusty-fork-dev:arm64 (0.3.0-1) ... 235s Selecting previously unselected package librust-wait-timeout-dev:arm64. 235s Preparing to unpack .../427-librust-wait-timeout-dev_0.2.0-1_arm64.deb ... 235s Unpacking librust-wait-timeout-dev:arm64 (0.2.0-1) ... 235s Selecting previously unselected package librust-rusty-fork+wait-timeout-dev:arm64. 235s Preparing to unpack .../428-librust-rusty-fork+wait-timeout-dev_0.3.0-1_arm64.deb ... 235s Unpacking librust-rusty-fork+wait-timeout-dev:arm64 (0.3.0-1) ... 235s Selecting previously unselected package librust-unarray-dev:arm64. 235s Preparing to unpack .../429-librust-unarray-dev_0.1.4-1_arm64.deb ... 235s Unpacking librust-unarray-dev:arm64 (0.1.4-1) ... 235s Selecting previously unselected package librust-proptest-dev:arm64. 235s Preparing to unpack .../430-librust-proptest-dev_1.5.0-2_arm64.deb ... 235s Unpacking librust-proptest-dev:arm64 (1.5.0-2) ... 235s Selecting previously unselected package llvm-19-runtime. 235s Preparing to unpack .../431-llvm-19-runtime_1%3a19.1.2-1ubuntu1_arm64.deb ... 235s Unpacking llvm-19-runtime (1:19.1.2-1ubuntu1) ... 235s Selecting previously unselected package llvm-runtime:arm64. 235s Preparing to unpack .../432-llvm-runtime_1%3a19.0-60~exp1_arm64.deb ... 235s Unpacking llvm-runtime:arm64 (1:19.0-60~exp1) ... 235s Selecting previously unselected package llvm-19-linker-tools. 235s Preparing to unpack .../433-llvm-19-linker-tools_1%3a19.1.2-1ubuntu1_arm64.deb ... 235s Unpacking llvm-19-linker-tools (1:19.1.2-1ubuntu1) ... 235s Selecting previously unselected package libpfm4:arm64. 235s Preparing to unpack .../434-libpfm4_4.13.0+git83-g91970fe-1_arm64.deb ... 235s Unpacking libpfm4:arm64 (4.13.0+git83-g91970fe-1) ... 236s Selecting previously unselected package llvm-19. 236s Preparing to unpack .../435-llvm-19_1%3a19.1.2-1ubuntu1_arm64.deb ... 236s Unpacking llvm-19 (1:19.1.2-1ubuntu1) ... 236s Selecting previously unselected package llvm. 236s Preparing to unpack .../436-llvm_1%3a19.0-60~exp1_arm64.deb ... 236s Unpacking llvm (1:19.0-60~exp1) ... 236s Selecting previously unselected package binutils-mingw-w64-x86-64. 236s Preparing to unpack .../437-binutils-mingw-w64-x86-64_2.43.1-4ubuntu1+12_arm64.deb ... 236s Unpacking binutils-mingw-w64-x86-64 (2.43.1-4ubuntu1+12) ... 236s Selecting previously unselected package binutils-mingw-w64-i686. 236s Preparing to unpack .../438-binutils-mingw-w64-i686_2.43.1-4ubuntu1+12_arm64.deb ... 236s Unpacking binutils-mingw-w64-i686 (2.43.1-4ubuntu1+12) ... 237s Selecting previously unselected package librust-python3-dll-a-dev:arm64. 237s Preparing to unpack .../439-librust-python3-dll-a-dev_0.2.10-1_arm64.deb ... 237s Unpacking librust-python3-dll-a-dev:arm64 (0.2.10-1) ... 237s Selecting previously unselected package librust-target-lexicon-dev:arm64. 237s Preparing to unpack .../440-librust-target-lexicon-dev_0.12.14-1_arm64.deb ... 237s Unpacking librust-target-lexicon-dev:arm64 (0.12.14-1) ... 237s Selecting previously unselected package librust-pyo3-build-config-dev:arm64. 237s Preparing to unpack .../441-librust-pyo3-build-config-dev_0.22.6-1_arm64.deb ... 237s Unpacking librust-pyo3-build-config-dev:arm64 (0.22.6-1) ... 237s Selecting previously unselected package python3.12-dev. 237s Preparing to unpack .../442-python3.12-dev_3.12.7-3_arm64.deb ... 237s Unpacking python3.12-dev (3.12.7-3) ... 237s Selecting previously unselected package librust-pyo3-ffi-dev:arm64. 237s Preparing to unpack .../443-librust-pyo3-ffi-dev_0.22.6-1build1_arm64.deb ... 237s Unpacking librust-pyo3-ffi-dev:arm64 (0.22.6-1build1) ... 237s Selecting previously unselected package librust-pyo3-macros-backend-dev:arm64. 237s Preparing to unpack .../444-librust-pyo3-macros-backend-dev_0.22.6-1_arm64.deb ... 237s Unpacking librust-pyo3-macros-backend-dev:arm64 (0.22.6-1) ... 237s Selecting previously unselected package librust-pyo3-macros-dev:arm64. 237s Preparing to unpack .../445-librust-pyo3-macros-dev_0.22.6-1_arm64.deb ... 237s Unpacking librust-pyo3-macros-dev:arm64 (0.22.6-1) ... 237s Selecting previously unselected package librust-rust-decimal-dev:arm64. 237s Preparing to unpack .../446-librust-rust-decimal-dev_1.36.0-1_arm64.deb ... 237s Unpacking librust-rust-decimal-dev:arm64 (1.36.0-1) ... 237s Selecting previously unselected package librust-unindent-dev:arm64. 237s Preparing to unpack .../447-librust-unindent-dev_0.2.3-1_arm64.deb ... 237s Unpacking librust-unindent-dev:arm64 (0.2.3-1) ... 237s Selecting previously unselected package librust-pyo3-dev:arm64. 237s Preparing to unpack .../448-librust-pyo3-dev_0.22.6-1_arm64.deb ... 237s Unpacking librust-pyo3-dev:arm64 (0.22.6-1) ... 237s Selecting previously unselected package librust-rustc-hash-dev:arm64. 237s Preparing to unpack .../449-librust-rustc-hash-dev_1.1.0-1_arm64.deb ... 237s Unpacking librust-rustc-hash-dev:arm64 (1.1.0-1) ... 237s Selecting previously unselected package pybuild-plugin-autopkgtest. 237s Preparing to unpack .../450-pybuild-plugin-autopkgtest_6.20241024_all.deb ... 237s Unpacking pybuild-plugin-autopkgtest (6.20241024) ... 237s Selecting previously unselected package python3-packaging. 237s Preparing to unpack .../451-python3-packaging_24.2-1_all.deb ... 237s Unpacking python3-packaging (24.2-1) ... 237s Selecting previously unselected package python3-pyproject-hooks. 237s Preparing to unpack .../452-python3-pyproject-hooks_1.2.0-1_all.deb ... 237s Unpacking python3-pyproject-hooks (1.2.0-1) ... 237s Selecting previously unselected package python3-toml. 237s Preparing to unpack .../453-python3-toml_0.10.2-1_all.deb ... 237s Unpacking python3-toml (0.10.2-1) ... 237s Selecting previously unselected package python3-wheel. 237s Preparing to unpack .../454-python3-wheel_0.45.1-1_all.deb ... 237s Unpacking python3-wheel (0.45.1-1) ... 237s Selecting previously unselected package python3-build. 237s Preparing to unpack .../455-python3-build_1.2.2-1_all.deb ... 237s Unpacking python3-build (1.2.2-1) ... 237s Selecting previously unselected package python3-installer. 238s Preparing to unpack .../456-python3-installer_0.7.0+dfsg1-3_all.deb ... 238s Unpacking python3-installer (0.7.0+dfsg1-3) ... 238s Selecting previously unselected package pybuild-plugin-pyproject. 238s Preparing to unpack .../457-pybuild-plugin-pyproject_6.20241024_all.deb ... 238s Unpacking pybuild-plugin-pyproject (6.20241024) ... 238s Selecting previously unselected package python3.13. 238s Preparing to unpack .../458-python3.13_3.13.0-2_arm64.deb ... 238s Unpacking python3.13 (3.13.0-2) ... 238s Selecting previously unselected package python3-all. 238s Preparing to unpack .../459-python3-all_3.12.7-1_arm64.deb ... 238s Unpacking python3-all (3.12.7-1) ... 238s Selecting previously unselected package python3-dateutil. 238s Preparing to unpack .../460-python3-dateutil_2.9.0-3_all.deb ... 238s Unpacking python3-dateutil (2.9.0-3) ... 238s Selecting previously unselected package python3-sortedcontainers. 238s Preparing to unpack .../461-python3-sortedcontainers_2.4.0-2_all.deb ... 238s Unpacking python3-sortedcontainers (2.4.0-2) ... 238s Selecting previously unselected package python3-hypothesis. 238s Preparing to unpack .../462-python3-hypothesis_6.119.3-1_all.deb ... 238s Unpacking python3-hypothesis (6.119.3-1) ... 238s Selecting previously unselected package python3-iniconfig. 238s Preparing to unpack .../463-python3-iniconfig_1.1.1-2_all.deb ... 238s Unpacking python3-iniconfig (1.1.1-2) ... 238s Selecting previously unselected package python3-pluggy. 238s Preparing to unpack .../464-python3-pluggy_1.5.0-1_all.deb ... 238s Unpacking python3-pluggy (1.5.0-1) ... 238s Selecting previously unselected package python3-pytest. 238s Preparing to unpack .../465-python3-pytest_8.3.3-1_all.deb ... 238s Unpacking python3-pytest (8.3.3-1) ... 238s Selecting previously unselected package python3-regex. 238s Preparing to unpack .../466-python3-regex_0.1.20240724-1build1_arm64.deb ... 238s Unpacking python3-regex (0.1.20240724-1build1) ... 238s Selecting previously unselected package python3-semantic-version. 238s Preparing to unpack .../467-python3-semantic-version_2.10.0-2_all.deb ... 238s Unpacking python3-semantic-version (2.10.0-2) ... 238s Selecting previously unselected package rustc. 238s Preparing to unpack .../468-rustc_1.80.1ubuntu2_arm64.deb ... 238s Unpacking rustc (1.80.1ubuntu2) ... 238s Selecting previously unselected package cargo. 238s Preparing to unpack .../469-cargo_1.80.1ubuntu2_arm64.deb ... 238s Unpacking cargo (1.80.1ubuntu2) ... 238s Selecting previously unselected package python3-setuptools-rust. 238s Preparing to unpack .../470-python3-setuptools-rust_1.9.0+dfsg-2_all.deb ... 238s Unpacking python3-setuptools-rust (1.9.0+dfsg-2) ... 238s Selecting previously unselected package python3-tiktoken. 238s Preparing to unpack .../471-python3-tiktoken_0.8.0-1build1_arm64.deb ... 238s Unpacking python3-tiktoken (0.8.0-1build1) ... 238s Setting up dh-python (6.20241024) ... 239s Setting up librust-ciborium-io-dev:arm64 (0.2.2-1) ... 239s Setting up librust-crossbeam-utils-dev:arm64 (0.8.19-1) ... 239s Setting up librust-parking-dev:arm64 (2.2.0-1) ... 239s Setting up librust-ppv-lite86-dev:arm64 (0.2.16-1) ... 239s Setting up python3-iniconfig (1.1.1-2) ... 239s Setting up libsharpyuv0:arm64 (1.4.0-0.1) ... 239s Setting up librust-pin-utils-dev:arm64 (0.1.0-1) ... 239s Setting up librust-fnv-dev:arm64 (1.0.7-1) ... 239s Setting up librust-unindent-dev:arm64 (0.2.3-1) ... 239s Setting up librust-quick-error-dev:arm64 (2.0.1-1) ... 239s Setting up librust-traitobject-dev:arm64 (0.1.0-1) ... 239s Setting up librust-either-dev:arm64 (1.13.0-1) ... 239s Setting up binutils-mingw-w64-x86-64 (2.43.1-4ubuntu1+12) ... 239s Setting up librust-adler-dev:arm64 (1.0.2-2) ... 239s Setting up librust-version-check-dev:arm64 (0.9.5-1) ... 239s Setting up librust-base64-dev:arm64 (0.21.7-1) ... 239s Setting up librust-indoc-dev:arm64 (2.0.5-1) ... 239s Setting up librust-anstyle-dev:arm64 (1.0.8-1) ... 239s Setting up librust-winapi-i686-pc-windows-gnu-dev:arm64 (0.4.0-1) ... 239s Setting up librust-futures-task-dev:arm64 (0.3.30-1) ... 239s Setting up librust-rustc-hash-dev:arm64 (1.1.0-1) ... 239s Setting up librust-wasm-bindgen-shared-dev:arm64 (0.2.87-1) ... 239s Setting up libarchive-zip-perl (1.68-1) ... 239s Setting up librust-colorchoice-dev:arm64 (1.0.0-1) ... 239s Setting up librust-fastrand-dev:arm64 (2.1.1-1) ... 239s Setting up libdebhelper-perl (13.20ubuntu1) ... 239s Setting up librust-unsafe-any-dev:arm64 (0.4.2-2) ... 239s Setting up librust-tinyvec-macros-dev:arm64 (0.1.0-1) ... 239s Setting up librust-libm-dev:arm64 (0.2.8-1) ... 239s Setting up librust-strsim-dev:arm64 (0.11.1-1) ... 239s Setting up libwebpdecoder3:arm64 (1.4.0-0.1) ... 239s Setting up m4 (1.4.19-4build1) ... 239s Setting up librust-rustc-demangle-dev:arm64 (0.1.21-1) ... 239s Setting up librust-const-cstr-dev:arm64 (0.3.0-1) ... 239s Setting up librust-fallible-iterator-dev:arm64 (0.3.0-2) ... 239s Setting up librust-ryu-dev:arm64 (1.0.15-1) ... 239s Setting up python3-sortedcontainers (2.4.0-2) ... 239s Setting up librust-humantime-dev:arm64 (2.1.0-1) ... 239s Setting up librust-anstyle-query-dev:arm64 (1.0.0-1) ... 239s Setting up librust-cast-dev:arm64 (0.3.0-1) ... 239s Setting up libgomp1:arm64 (14.2.0-9ubuntu1) ... 239s Setting up librust-subtle-dev:arm64 (2.6.1-1) ... 239s Setting up librust-simdutf8-dev:arm64 (0.1.4-4) ... 239s Setting up librust-atomic-waker-dev:arm64 (1.1.2-1) ... 239s Setting up librust-miniz-oxide-dev:arm64 (0.7.1-1) ... 239s Setting up librust-pin-project-lite-dev:arm64 (0.2.13-1) ... 239s Setting up python3-wheel (0.45.1-1) ... 239s Setting up librust-unicode-segmentation-dev:arm64 (1.11.0-1) ... 239s Setting up librust-typemap-dev:arm64 (0.3.3-2) ... 239s Setting up libpython3.13-minimal:arm64 (3.13.0-2) ... 239s Setting up librust-compiler-builtins-dev:arm64 (0.1.101-1) ... 239s Setting up librust-weezl-dev:arm64 (0.1.5-1) ... 239s Setting up librust-utf8parse-dev:arm64 (0.2.1-1) ... 239s Setting up librust-crossbeam-epoch-dev:arm64 (0.9.18-1) ... 239s Setting up autotools-dev (20220109.1) ... 239s Setting up librust-tap-dev:arm64 (1.0.1-1) ... 239s Setting up python3-packaging (24.2-1) ... 240s Setting up librust-array-init-dev:arm64 (2.0.1-1) ... 240s Setting up libpkgconf3:arm64 (1.8.1-4) ... 240s Setting up libpfm4:arm64 (4.13.0+git83-g91970fe-1) ... 240s Setting up librust-oorandom-dev:arm64 (11.1.3-1) ... 240s Setting up libexpat1-dev:arm64 (2.6.4-1) ... 240s Setting up python3-pyproject-hooks (1.2.0-1) ... 240s Setting up librust-rustc-std-workspace-core-dev:arm64 (1.0.0-1) ... 240s Setting up librust-funty-dev:arm64 (2.0.0-1) ... 240s Setting up librust-futures-io-dev:arm64 (0.3.31-1) ... 240s Setting up librust-typenum-dev:arm64 (1.17.0-2) ... 240s Setting up uuid-dev:arm64 (2.40.2-1ubuntu1) ... 240s Setting up librust-core-maths-dev:arm64 (0.1.0-2) ... 240s Setting up librust-stable-deref-trait-dev:arm64 (1.2.0-1) ... 240s Setting up librust-critical-section-dev:arm64 (1.1.3-1) ... 240s Setting up librust-scopeguard-dev:arm64 (1.2.0-1) ... 240s Setting up librust-iana-time-zone-dev:arm64 (0.1.60-1) ... 240s Setting up fonts-dejavu-mono (2.37-8) ... 240s Setting up libmpc3:arm64 (1.3.1-1build2) ... 240s Setting up librust-rand-core-dev:arm64 (0.6.4-2) ... 240s Setting up python3-semantic-version (2.10.0-2) ... 240s Setting up autopoint (0.22.5-2) ... 240s Setting up libjsoncpp25:arm64 (1.9.5-6build1) ... 240s Setting up fonts-dejavu-core (2.37-8) ... 240s Setting up librust-seahash-dev:arm64 (4.1.0-1) ... 240s Setting up pkgconf-bin (1.8.1-4) ... 240s Setting up librust-ab-glyph-rasterizer-dev:arm64 (0.1.7-1) ... 240s Setting up binutils-mingw-w64-i686 (2.43.1-4ubuntu1+12) ... 240s Setting up librust-time-core-dev:arm64 (0.1.2-1) ... 240s Setting up python3-regex (0.1.20240724-1build1) ... 241s Setting up librust-crunchy-dev:arm64 (0.2.2-1) ... 241s Setting up python3-toml (0.10.2-1) ... 241s Setting up librust-unicase-dev:arm64 (2.7.0-1) ... 241s Setting up librust-unicode-width-dev:arm64 (0.1.14-1) ... 241s Setting up python3-installer (0.7.0+dfsg1-3) ... 241s Setting up autoconf (2.72-3) ... 241s Setting up python3-pluggy (1.5.0-1) ... 241s Setting up libwebp7:arm64 (1.4.0-0.1) ... 241s Setting up libubsan1:arm64 (14.2.0-9ubuntu1) ... 241s Setting up zlib1g-dev:arm64 (1:1.3.dfsg+really1.3.1-1ubuntu1) ... 241s Setting up librust-unicode-ident-dev:arm64 (1.0.13-1) ... 241s Setting up librust-equivalent-dev:arm64 (1.0.1-1) ... 241s Setting up dwz (0.15-1build6) ... 241s Setting up librust-bitflags-1-dev:arm64 (1.3.2-5) ... 241s Setting up librust-uncased-dev:arm64 (0.9.6-2) ... 241s Setting up librust-slog-dev:arm64 (2.7.0-1) ... 241s Setting up python3-tiktoken (0.8.0-1build1) ... 242s Setting up librust-pure-rust-locales-dev:arm64 (0.8.1-1) ... 242s Setting up libhwasan0:arm64 (14.2.0-9ubuntu1) ... 242s Setting up librhash0:arm64 (1.4.3-3build1) ... 242s Setting up libasan8:arm64 (14.2.0-9ubuntu1) ... 242s Setting up librust-ttf-parser-dev:arm64 (0.24.1-1) ... 242s Setting up librust-cfg-if-dev:arm64 (1.0.0-1) ... 242s Setting up debugedit (1:5.1-1) ... 242s Setting up librust-color-quant-dev:arm64 (1.1.0-1) ... 242s Setting up python3.13-minimal (3.13.0-2) ... 242s Setting up python3-dateutil (2.9.0-3) ... 243s Setting up librust-blobby-dev:arm64 (0.3.1-1) ... 243s Setting up cmake-data (3.30.3-1) ... 243s Setting up llvm-19-linker-tools (1:19.1.2-1ubuntu1) ... 243s Setting up librust-byteorder-dev:arm64 (1.5.0-1) ... 243s Setting up libtsan2:arm64 (14.2.0-9ubuntu1) ... 243s Setting up librust-static-assertions-dev:arm64 (1.1.0-1) ... 243s Setting up librust-compiler-builtins+core-dev:arm64 (0.1.101-1) ... 243s Setting up librust-float-ord-dev:arm64 (0.3.2-1) ... 243s Setting up librust-autocfg-dev:arm64 (1.1.0-1) ... 243s Setting up libisl23:arm64 (0.27-1) ... 243s Setting up librust-time-macros-dev:arm64 (0.2.16-1) ... 243s Setting up llvm-19-runtime (1:19.1.2-1ubuntu1) ... 243s Setting up librust-futures-sink-dev:arm64 (0.3.31-1) ... 243s Setting up python3-build (1.2.2-1) ... 243s Setting up libsharpyuv-dev:arm64 (1.4.0-0.1) ... 243s Setting up librust-cfg-if-0.1-dev:arm64 (0.1.10-3) ... 243s Setting up librust-tinyvec-dev:arm64 (1.6.0-2) ... 243s Setting up libwebpmux3:arm64 (1.4.0-0.1) ... 243s Setting up librust-plotters-backend-dev:arm64 (0.3.7-1) ... 243s Setting up librust-shlex-dev:arm64 (1.3.0-1) ... 243s Setting up libpython3.13-stdlib:arm64 (3.13.0-2) ... 243s Setting up librust-indenter-dev:arm64 (0.3.3-1) ... 243s Setting up librust-cpp-demangle-dev:arm64 (0.4.0-1) ... 243s Setting up librust-winapi-x86-64-pc-windows-gnu-dev:arm64 (0.4.0-1) ... 243s Setting up libcc1-0:arm64 (14.2.0-9ubuntu1) ... 243s Setting up libbrotli-dev:arm64 (1.1.0-2build3) ... 243s Setting up liblsan0:arm64 (14.2.0-9ubuntu1) ... 243s Setting up libitm1:arm64 (14.2.0-9ubuntu1) ... 243s Setting up librust-clap-lex-dev:arm64 (0.7.2-2) ... 243s Setting up libhttp-parser2.9:arm64 (2.9.4-6build1) ... 243s Setting up librust-unarray-dev:arm64 (0.1.4-1) ... 243s Setting up libstd-rust-1.80:arm64 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 243s Setting up librust-itertools-dev:arm64 (0.10.5-1) ... 243s Setting up librust-heck-dev:arm64 (0.4.1-1) ... 243s Setting up libbz2-dev:arm64 (1.0.8-6) ... 243s Setting up librust-num-conv-dev:arm64 (0.1.0-1) ... 243s Setting up libpython3.13:arm64 (3.13.0-2) ... 243s Setting up automake (1:1.16.5-1.3ubuntu1) ... 243s update-alternatives: using /usr/bin/automake-1.16 to provide /usr/bin/automake (automake) in auto mode 243s Setting up libfile-stripnondeterminism-perl (1.14.0-1) ... 243s Setting up librust-owned-ttf-parser-dev:arm64 (0.24.0-1) ... 243s Setting up librust-crossbeam-epoch+std-dev:arm64 (0.9.18-1) ... 243s Setting up librust-libc-dev:arm64 (0.2.161-1) ... 243s Setting up librust-is-terminal-dev:arm64 (0.4.13-1) ... 243s Setting up gettext (0.22.5-2) ... 243s Setting up librust-gif-dev:arm64 (0.11.3-1) ... 243s Setting up librust-crossbeam-deque-dev:arm64 (0.8.5-1) ... 243s Setting up librust-tiny-keccak-dev:arm64 (2.0.2-1) ... 243s Setting up python3.13 (3.13.0-2) ... 244s Setting up librust-linux-raw-sys-dev:arm64 (0.4.14-1) ... 244s Setting up pybuild-plugin-pyproject (6.20241024) ... 244s Setting up fontconfig-config (2.15.0-1.1ubuntu2) ... 244s Setting up librust-getrandom-dev:arm64 (0.2.12-1) ... 244s Setting up python3-pytest (8.3.3-1) ... 245s Setting up librust-libloading-dev:arm64 (0.8.5-1) ... 245s Setting up librust-socket2-dev:arm64 (0.5.7-1) ... 245s Setting up librust-memmap2-dev:arm64 (0.9.3-1) ... 245s Setting up libwebpdemux2:arm64 (1.4.0-0.1) ... 245s Setting up python3-hypothesis (6.119.3-1) ... 246s Setting up librust-ab-glyph-rasterizer+libm-dev:arm64 (0.1.7-1) ... 246s Setting up libpng-dev:arm64 (1.6.44-2) ... 246s Setting up librust-tinyvec+tinyvec-macros-dev:arm64 (1.6.0-2) ... 246s Setting up librust-owning-ref-dev:arm64 (0.4.1-1) ... 246s Setting up librust-num-cpus-dev:arm64 (1.16.0-1) ... 246s Setting up librust-memoffset-dev:arm64 (0.8.0-1) ... 246s Setting up python3-all (3.12.7-1) ... 246s Setting up librust-cpufeatures-dev:arm64 (0.2.11-1) ... 246s Setting up libpython3.12-dev:arm64 (3.12.7-3) ... 246s Setting up librust-proc-macro2-dev:arm64 (1.0.86-1) ... 246s Setting up librust-compiler-builtins+rustc-dep-of-std-dev:arm64 (0.1.101-1) ... 246s Setting up librust-rayon-core-dev:arm64 (1.12.1-1) ... 246s Setting up librust-winapi-dev:arm64 (0.3.9-1) ... 246s Setting up pkgconf:arm64 (1.8.1-4) ... 246s Setting up librust-ab-glyph-dev:arm64 (0.2.28-1) ... 246s Setting up libstd-rust-1.80-dev:arm64 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 246s Setting up libfreetype-dev:arm64 (2.13.3+dfsg-1) ... 246s Setting up intltool-debian (0.35.0+20060710.6) ... 246s Setting up librust-rand-core+getrandom-dev:arm64 (0.6.4-2) ... 246s Setting up librust-rand-xorshift-dev:arm64 (0.3.0-2) ... 246s Setting up librust-signal-hook-registry-dev:arm64 (1.4.0-1) ... 246s Setting up libwebp-dev:arm64 (1.4.0-0.1) ... 246s Setting up librust-errno-dev:arm64 (0.3.8-1) ... 246s Setting up librust-anes-dev:arm64 (0.1.6-1) ... 246s Setting up libpython3.13-dev:arm64 (3.13.0-2) ... 246s Setting up llvm-runtime:arm64 (1:19.0-60~exp1) ... 246s Setting up python3.12-dev (3.12.7-3) ... 246s Setting up librust-jobserver-dev:arm64 (0.1.32-1) ... 246s Setting up pkg-config:arm64 (1.8.1-4) ... 246s Setting up dh-strip-nondeterminism (1.14.0-1) ... 246s Setting up librust-crc32fast-dev:arm64 (1.4.2-1) ... 246s Setting up cpp-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 246s Setting up librust-num-traits-dev:arm64 (0.2.19-2) ... 246s Setting up librust-winapi-util-dev:arm64 (0.1.6-1) ... 246s Setting up librust-wait-timeout-dev:arm64 (0.2.0-1) ... 246s Setting up cmake (3.30.3-1) ... 246s Setting up libgit2-1.7:arm64 (1.7.2+ds-1ubuntu3) ... 246s Setting up llvm-19 (1:19.1.2-1ubuntu1) ... 246s Setting up libgcc-14-dev:arm64 (14.2.0-9ubuntu1) ... 246s Setting up librust-same-file-dev:arm64 (1.0.6-1) ... 246s Setting up librust-rayon-dev:arm64 (1.10.0-1) ... 246s Setting up librust-termcolor-dev:arm64 (1.4.1-1) ... 246s Setting up librust-pkg-config-dev:arm64 (0.3.27-1) ... 246s Setting up libstdc++-14-dev:arm64 (14.2.0-9ubuntu1) ... 246s Setting up librust-jpeg-decoder-dev:arm64 (0.3.0-1) ... 246s Setting up librust-dirs-sys-next-dev:arm64 (0.1.1-1) ... 246s Setting up librust-num-integer-dev:arm64 (0.1.46-1) ... 246s Setting up librust-dirs-next-dev:arm64 (2.0.0-1) ... 246s Setting up librust-num-threads-dev:arm64 (0.1.7-1) ... 246s Setting up libpython3-dev:arm64 (3.12.7-1) ... 246s Setting up librust-dlib-dev:arm64 (0.5.2-2) ... 246s Setting up librust-libwebp-sys-dev:arm64 (0.9.5-1build1) ... 246s Setting up po-debconf (1.0.21+nmu1) ... 246s Setting up librust-quote-dev:arm64 (1.0.37-1) ... 246s Setting up librust-libz-sys-dev:arm64 (1.1.20-1) ... 246s Setting up librust-syn-dev:arm64 (2.0.85-1) ... 246s Setting up librust-rand-core+std-dev:arm64 (0.6.4-2) ... 246s Setting up librust-powerfmt-macros-dev:arm64 (0.1.0-1) ... 246s Setting up cpp-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 246s Setting up librust-powerfmt-dev:arm64 (0.2.0-1) ... 246s Setting up librust-sval-derive-dev:arm64 (2.6.1-2) ... 246s Setting up libpython3-all-dev:arm64 (3.12.7-1) ... 246s Setting up librust-cc-dev:arm64 (1.1.14-1) ... 246s Setting up librust-zeroize-derive-dev:arm64 (1.4.2-1) ... 246s Setting up llvm (1:19.0-60~exp1) ... 246s Setting up librust-postgres-derive-dev:arm64 (0.4.5-1) ... 246s Setting up librust-syn-1-dev:arm64 (1.0.109-3) ... 246s Setting up cpp-14 (14.2.0-9ubuntu1) ... 246s Setting up librust-clap-derive-dev:arm64 (4.5.13-2) ... 246s Setting up librust-bytecheck-derive-dev:arm64 (0.6.12-1) ... 246s Setting up librust-no-panic-dev:arm64 (0.1.13-1) ... 246s Setting up cpp (4:14.1.0-2ubuntu1) ... 246s Setting up librust-serde-derive-dev:arm64 (1.0.210-1) ... 246s Setting up librust-walkdir-dev:arm64 (2.5.0-1) ... 246s Setting up gcc-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 246s Setting up librust-zerocopy-derive-dev:arm64 (0.7.32-2) ... 246s Setting up librust-sha1-asm-dev:arm64 (0.5.1-2) ... 246s Setting up librust-valuable-derive-dev:arm64 (0.1.0-1) ... 246s Setting up librust-ghost-dev:arm64 (0.1.5-1) ... 246s Setting up librust-serde-dev:arm64 (1.0.210-2) ... 246s Setting up librust-bytemuck-derive-dev:arm64 (1.5.0-2) ... 246s Setting up librust-derive-arbitrary-dev:arm64 (1.3.2-1) ... 246s Setting up librust-allocator-api2-dev:arm64 (0.2.16-1) ... 246s Setting up librust-cmake-dev:arm64 (0.1.45-1) ... 246s Setting up librust-async-attributes-dev (1.1.2-6) ... 246s Setting up librust-rand-chacha-dev:arm64 (0.3.1-2) ... 246s Setting up gcc-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 246s Setting up librust-futures-macro-dev:arm64 (0.3.30-1) ... 246s Setting up librust-ctor-dev:arm64 (0.1.26-1) ... 246s Setting up librust-unicode-bidi-dev:arm64 (0.3.13-1) ... 246s Setting up g++-14-aarch64-linux-gnu (14.2.0-9ubuntu1) ... 246s Setting up librust-tracing-attributes-dev:arm64 (0.1.27-1) ... 246s Setting up librust-ptr-meta-derive-dev:arm64 (0.1.4-1) ... 246s Setting up librust-serde-fmt-dev (1.0.3-3) ... 246s Setting up librust-sha2-asm-dev:arm64 (0.6.2-2) ... 246s Setting up librust-portable-atomic-dev:arm64 (1.9.0-4) ... 246s Setting up librust-tokio-macros-dev:arm64 (2.4.0-2) ... 246s Setting up librust-flate2-dev:arm64 (1.0.34-1) ... 246s Setting up librust-freetype-sys-dev:arm64 (0.13.1-1) ... 246s Setting up librust-lock-api-dev:arm64 (0.4.12-1) ... 246s Setting up librust-ptr-meta-dev:arm64 (0.1.4-1) ... 246s Setting up librust-inventory-dev:arm64 (0.3.2-1) ... 246s Setting up librust-sval-dev:arm64 (2.6.1-2) ... 246s Setting up librust-itoa-dev:arm64 (1.0.9-1) ... 246s Setting up gcc-14 (14.2.0-9ubuntu1) ... 246s Setting up librust-bytes-dev:arm64 (1.8.0-1) ... 246s Setting up librust-bumpalo-dev:arm64 (3.16.0-1) ... 246s Setting up librust-python3-dll-a-dev:arm64 (0.2.10-1) ... 246s Setting up librust-siphasher-dev:arm64 (0.3.10-1) ... 246s Setting up librust-rand-core+serde-dev:arm64 (0.6.4-2) ... 246s Setting up librust-sval-ref-dev:arm64 (2.6.1-1) ... 246s Setting up librust-rkyv-derive-dev:arm64 (0.7.44-1) ... 246s Setting up librust-zerocopy-dev:arm64 (0.7.32-1) ... 246s Setting up librust-md5-asm-dev:arm64 (0.5.0-2) ... 246s Setting up librust-semver-dev:arm64 (1.0.23-1) ... 246s Setting up librust-freetype-dev:arm64 (0.7.0-4) ... 246s Setting up librust-bytemuck-dev:arm64 (1.14.0-1) ... 246s Setting up librust-bit-vec-dev:arm64 (0.6.3-1) ... 246s Setting up librust-zeroize-dev:arm64 (1.8.1-1) ... 246s Setting up librust-slab-dev:arm64 (0.4.9-1) ... 246s Setting up librust-arbitrary-dev:arm64 (1.3.2-1) ... 246s Setting up librust-valuable-dev:arm64 (0.1.0-4) ... 246s Setting up librust-target-lexicon-dev:arm64 (0.12.14-1) ... 246s Setting up librust-serde-test-dev:arm64 (1.0.171-1) ... 246s Setting up g++-aarch64-linux-gnu (4:14.1.0-2ubuntu1) ... 246s Setting up librust-bit-set-dev:arm64 (0.5.2-1) ... 246s Setting up librust-concurrent-queue-dev:arm64 (2.5.0-4) ... 246s Setting up g++-14 (14.2.0-9ubuntu1) ... 246s Setting up librust-erased-serde-dev:arm64 (0.3.31-1) ... 246s Setting up librust-radium-dev:arm64 (1.1.0-1) ... 246s Setting up librust-bit-set+std-dev:arm64 (0.5.2-1) ... 246s Setting up librust-phf-shared-dev:arm64 (0.11.2-1) ... 246s Setting up librust-tiff-dev:arm64 (0.9.0-1) ... 246s Setting up librust-smol-str-dev:arm64 (0.2.0-1) ... 246s Setting up librust-atomic-dev:arm64 (0.6.0-1) ... 246s Setting up librust-generic-array-dev:arm64 (0.14.7-1) ... 246s Setting up librust-half-dev:arm64 (1.8.2-4) ... 246s Setting up librust-phf-dev:arm64 (0.11.2-1) ... 246s Setting up librust-spin-dev:arm64 (0.9.8-4) ... 246s Setting up librust-sval-dynamic-dev:arm64 (2.6.1-1) ... 246s Setting up librust-qoi-dev:arm64 (0.4.1-2) ... 246s Setting up librust-async-task-dev (4.7.1-3) ... 246s Setting up librust-crypto-common-dev:arm64 (0.1.6-1) ... 246s Setting up librust-ciborium-ll-dev:arm64 (0.2.2-1) ... 246s Setting up librust-futures-core-dev:arm64 (0.3.30-1) ... 246s Setting up librust-lazy-static-dev:arm64 (1.5.0-1) ... 246s Setting up libtool (2.4.7-8) ... 246s Setting up librust-sval-buffer-dev:arm64 (2.6.1-1) ... 246s Setting up librust-arrayvec-dev:arm64 (0.7.4-2) ... 246s Setting up librust-png-dev:arm64 (0.17.7-3) ... 246s Setting up librust-rustc-version-dev:arm64 (0.4.0-1) ... 246s Setting up librust-event-listener-dev (5.3.1-8) ... 246s Setting up librust-smallvec-dev:arm64 (1.13.2-1) ... 246s Setting up librust-sval-fmt-dev:arm64 (2.6.1-1) ... 246s Setting up librust-const-oid-dev:arm64 (0.9.3-1) ... 246s Setting up gcc (4:14.1.0-2ubuntu1) ... 246s Setting up librust-anstyle-parse-dev:arm64 (0.2.1-1) ... 246s Setting up rustc-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 246s Setting up dh-autoreconf (20) ... 246s Setting up librust-ciborium-dev:arm64 (0.2.2-2) ... 246s Setting up librust-block-buffer-dev:arm64 (0.10.2-2) ... 246s Setting up librust-pathfinder-simd-dev:arm64 (0.5.2-1) ... 246s Setting up librust-unicode-normalization-dev:arm64 (0.1.22-1) ... 246s Setting up librust-anstream-dev:arm64 (0.6.15-1) ... 246s Setting up librust-bitflags-dev:arm64 (2.6.0-1) ... 246s Setting up librust-regex-syntax-dev:arm64 (0.8.5-1) ... 246s Setting up g++ (4:14.1.0-2ubuntu1) ... 246s update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode 246s Setting up rustc (1.80.1ubuntu2) ... 246s Setting up librust-parking-lot-core-dev:arm64 (0.9.10-1) ... 246s Setting up build-essential (12.10ubuntu1) ... 246s Setting up librust-futures-channel-dev:arm64 (0.3.30-1) ... 246s Setting up cargo-1.80 (1.80.1+dfsg0ubuntu1-0ubuntu1) ... 246s Setting up librust-once-cell-dev:arm64 (1.20.2-1) ... 246s Setting up librust-pyo3-build-config-dev:arm64 (0.22.6-1) ... 246s Setting up librust-phf-shared+uncased-dev:arm64 (0.11.2-1) ... 246s Setting up librust-digest-dev:arm64 (0.10.7-2) ... 246s Setting up librust-md-5-dev:arm64 (0.10.6-1) ... 246s Setting up librust-sval-serde-dev:arm64 (2.6.1-1) ... 246s Setting up librust-parking-lot-dev:arm64 (0.12.3-1) ... 246s Setting up librust-event-listener-strategy-dev:arm64 (0.5.2-3) ... 246s Setting up librust-pyo3-macros-backend-dev:arm64 (0.22.6-1) ... 246s Setting up librust-pyo3-ffi-dev:arm64 (0.22.6-1build1) ... 246s Setting up librust-const-random-macro-dev:arm64 (0.1.16-2) ... 246s Setting up librust-const-random-dev:arm64 (0.1.17-2) ... 246s Setting up librust-pyo3-macros-dev:arm64 (0.22.6-1) ... 246s Setting up librust-sha1-dev:arm64 (0.10.6-1) ... 246s Setting up debhelper (13.20ubuntu1) ... 246s Setting up librust-ahash-dev (0.8.11-8) ... 246s Setting up librust-async-channel-dev (2.3.1-8) ... 246s Setting up librust-stringprep-dev:arm64 (0.1.2-1) ... 246s Setting up librust-tracing-core-dev:arm64 (0.1.32-1) ... 246s Setting up cargo (1.80.1ubuntu2) ... 246s Setting up librust-async-lock-dev (3.4.0-4) ... 246s Setting up python3-setuptools-rust (1.9.0+dfsg-2) ... 246s Setting up librust-eyre-dev:arm64 (0.6.12-1) ... 246s Setting up librust-sha2-dev:arm64 (0.10.8-1) ... 246s Setting up librust-hmac-dev:arm64 (0.12.1-1) ... 246s Setting up librust-rustix-dev:arm64 (0.38.37-1) ... 246s Setting up librust-wyz-dev:arm64 (0.5.1-1) ... 246s Setting up librust-bitvec-dev:arm64 (1.0.1-1) ... 246s Setting up librust-phf+uncased-dev:arm64 (0.11.2-1) ... 246s Setting up librust-value-bag-sval2-dev:arm64 (1.9.0-1) ... 246s Setting up librust-tempfile-dev:arm64 (3.13.0-1) ... 246s Setting up librust-eyre+default-dev:arm64 (0.6.12-1) ... 246s Setting up pybuild-plugin-autopkgtest (6.20241024) ... 246s Setting up librust-rusty-fork-dev:arm64 (0.3.0-1) ... 246s Setting up librust-hashbrown-dev:arm64 (0.14.5-5) ... 246s Setting up librust-rusty-fork+wait-timeout-dev:arm64 (0.3.0-1) ... 246s Setting up librust-terminal-size-dev:arm64 (0.3.0-2) ... 246s Setting up librust-indexmap-dev:arm64 (2.2.6-1) ... 246s Setting up librust-gimli-dev:arm64 (0.28.1-2) ... 246s Setting up librust-webp-dev:arm64 (0.2.6-1) ... 246s Setting up librust-memchr-dev:arm64 (2.7.4-1) ... 246s Setting up librust-futures-util-dev:arm64 (0.3.30-2) ... 246s Setting up librust-csv-core-dev:arm64 (0.1.11-1) ... 246s Setting up librust-futures-lite-dev:arm64 (2.3.0-2) ... 246s Setting up librust-csv-dev:arm64 (1.3.0-1) ... 246s Setting up librust-serde-json-dev:arm64 (1.0.128-1) ... 246s Setting up librust-async-executor-dev (1.13.1-1) ... 247s Setting up librust-futures-executor-dev:arm64 (0.3.30-1) ... 247s Setting up librust-value-bag-serde1-dev:arm64 (1.9.0-1) ... 247s Setting up librust-tinytemplate-dev:arm64 (1.2.1-1) ... 247s Setting up librust-futures-dev:arm64 (0.3.30-2) ... 247s Setting up librust-value-bag-dev:arm64 (1.9.0-1) ... 247s Setting up librust-log-dev:arm64 (0.4.22-1) ... 247s Setting up librust-kv-log-macro-dev (1.0.8-4) ... 247s Setting up librust-pathfinder-geometry-dev:arm64 (0.5.1-1) ... 247s Setting up librust-tracing-dev:arm64 (0.1.40-1) ... 247s Setting up librust-polling-dev:arm64 (3.4.0-1) ... 247s Setting up librust-aho-corasick-dev:arm64 (1.1.3-1) ... 247s Setting up librust-async-io-dev:arm64 (2.3.3-4) ... 247s Setting up librust-blocking-dev (1.6.1-5) ... 247s Setting up librust-async-net-dev (2.0.0-4) ... 247s Setting up librust-rand-dev:arm64 (0.8.5-1) ... 247s Setting up librust-mio-dev:arm64 (1.0.2-2) ... 247s Setting up librust-wasm-bindgen-backend-dev:arm64 (0.2.87-1) ... 247s Setting up librust-twox-hash-dev:arm64 (1.6.3-1) ... 247s Setting up librust-proptest-dev:arm64 (1.5.0-2) ... 247s Setting up librust-wasm-bindgen-macro-support-dev:arm64 (0.2.87-1) ... 247s Setting up librust-regex-automata-dev:arm64 (0.4.9-1) ... 247s Setting up librust-wasm-bindgen-macro-support+spans-dev:arm64 (0.2.87-1) ... 247s Setting up librust-wasm-bindgen-macro-dev:arm64 (0.2.87-1) ... 247s Setting up librust-uuid-dev:arm64 (1.10.0-1) ... 247s Setting up librust-bstr-dev:arm64 (1.7.0-2build1) ... 247s Setting up librust-async-signal-dev:arm64 (0.2.10-1) ... 247s Setting up librust-bytecheck-dev:arm64 (0.6.12-1) ... 247s Setting up librust-postgres-protocol-dev:arm64 (0.6.6-2) ... 247s Setting up librust-async-fs-dev (2.1.2-4) ... 247s Setting up librust-wasm-bindgen-dev:arm64 (0.2.87-1) ... 247s Setting up librust-convert-case-dev:arm64 (0.6.0-2) ... 247s Setting up librust-regex-dev:arm64 (1.10.6-1) ... 247s Setting up librust-fancy-regex-dev:arm64 (0.11.0-2) ... 247s Setting up librust-async-process-dev (2.3.0-1) ... 247s Setting up librust-wasm-bindgen-macro+spans-dev:arm64 (0.2.87-1) ... 247s Setting up librust-rend-dev:arm64 (0.4.0-1) ... 247s Setting up librust-derive-more-0.99-dev:arm64 (0.99.18-2) ... 247s Setting up librust-env-logger-dev:arm64 (0.10.2-2) ... 247s Setting up librust-wasm-bindgen+spans-dev:arm64 (0.2.87-1) ... 247s Setting up librust-wasm-bindgen+default-dev:arm64 (0.2.87-1) ... 247s Setting up librust-rkyv-dev:arm64 (0.7.44-1) ... 247s Setting up librust-eui48-dev:arm64 (1.1.0-2) ... 247s Setting up librust-parse-zoneinfo-dev:arm64 (0.3.0-1) ... 247s Setting up librust-smol-dev (2.0.2-1) ... 247s Setting up librust-js-sys-dev:arm64 (0.3.64-1) ... 247s Setting up librust-num-complex-dev:arm64 (0.4.6-2) ... 247s Setting up librust-approx-dev:arm64 (0.5.1-1) ... 247s Setting up librust-ruzstd-dev:arm64 (0.5.0-1) ... 247s Setting up librust-web-sys-dev:arm64 (0.3.64-2) ... 247s Setting up librust-quickcheck-dev:arm64 (1.0.3-3) ... 247s Setting up librust-geo-types-dev:arm64 (0.7.11-2) ... 247s Setting up librust-deranged-dev:arm64 (0.3.11-1) ... 247s Setting up librust-num-bigint-dev:arm64 (0.4.6-1) ... 247s Setting up librust-num-rational-dev:arm64 (0.4.2-1) ... 247s Setting up librust-chrono-dev:arm64 (0.4.38-2) ... 247s Setting up librust-object-dev:arm64 (0.32.2-1) ... 247s Setting up librust-image-dev:arm64 (0.24.7-2) ... 247s Setting up librust-time-dev:arm64 (0.3.36-2) ... 247s Setting up librust-plotters-bitmap-dev:arm64 (0.3.3-3) ... 247s Setting up librust-postgres-types-dev:arm64 (0.2.6-2) ... 247s Setting up librust-addr2line-dev:arm64 (0.21.0-2) ... 247s Setting up librust-plotters-svg-dev:arm64 (0.3.5-1) ... 247s Setting up librust-rust-decimal-dev:arm64 (1.36.0-1) ... 247s Setting up librust-backtrace-dev:arm64 (0.3.69-2) ... 247s Setting up librust-tokio-dev:arm64 (1.39.3-3) ... 247s Setting up librust-async-global-executor-dev:arm64 (2.4.1-5) ... 247s Setting up librust-clap-builder-dev:arm64 (4.5.15-2) ... 247s Setting up librust-clap-dev:arm64 (4.5.16-1) ... 247s Setting up librust-async-std-dev (1.13.0-1) ... 247s Setting up librust-anyhow-dev:arm64 (1.0.86-1) ... 247s Processing triggers for sgml-base (1.31) ... 247s Setting up libfontconfig1:arm64 (2.15.0-1.1ubuntu2) ... 247s Processing triggers for install-info (7.1.1-1) ... 247s Setting up libfontconfig-dev:arm64 (2.15.0-1.1ubuntu2) ... 247s Processing triggers for libc-bin (2.40-1ubuntu3) ... 247s Processing triggers for systemd (256.5-2ubuntu4) ... 247s Processing triggers for man-db (2.13.0-1) ... 249s Setting up librust-yeslogic-fontconfig-sys-dev:arm64 (3.0.1-1) ... 249s Setting up librust-font-kit-dev:arm64 (0.11.0-2) ... 249s Setting up librust-plotters-dev:arm64 (0.3.5-4) ... 249s Setting up librust-criterion-dev (0.5.1-6) ... 249s Setting up librust-phf-generator-dev:arm64 (0.11.2-2) ... 249s Setting up librust-phf-codegen-dev:arm64 (0.11.2-1) ... 249s Setting up librust-chrono-tz-build-dev:arm64 (0.2.1-1) ... 249s Setting up librust-chrono-tz-dev:arm64 (0.8.6-2) ... 249s Setting up librust-pyo3-dev:arm64 (0.22.6-1) ... 250s autopkgtest [09:39:07]: test pybuild-autopkgtest: pybuild-autopkgtest 250s autopkgtest [09:39:07]: test pybuild-autopkgtest: [----------------------- 250s pybuild-autopkgtest 251s I: pybuild base:311: cd /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build; python3.13 -m pytest tests 251s ============================= test session starts ============================== 251s platform linux -- Python 3.13.0, pytest-8.3.3, pluggy-1.5.0 251s rootdir: /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build 251s configfile: pyproject.toml 251s plugins: typeguard-4.4.1, hypothesis-6.119.3 251s collected 30 items 251s 851s tests/test_encoding.py FFFFFFFFFFFFFFFFFFFFFF [ 73%] 851s tests/test_misc.py F. [ 80%] 855s tests/test_offsets.py FF [ 86%] 855s tests/test_pickle.py F [ 90%] 858s tests/test_simple_public.py FF. [100%] 858s 858s =================================== FAILURES =================================== 858s _________________________________ test_simple __________________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_simple(): 858s > enc = tiktoken.get_encoding("gpt2") 858s 858s tests/test_encoding.py:15: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 858s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 858s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _____________________________ test_simple_repeated _____________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_simple_repeated(): 858s > enc = tiktoken.get_encoding("gpt2") 858s 858s tests/test_encoding.py:32: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 858s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 858s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________________ test_simple_regex _______________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_simple_regex(): 858s > enc = tiktoken.get_encoding("cl100k_base") 858s 858s tests/test_encoding.py:53: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________________ test_basic_encode _______________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_basic_encode(): 858s > enc = tiktoken.get_encoding("r50k_base") 858s 858s tests/test_encoding.py:62: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________________ test_encode_empty _______________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_encode_empty(): 858s > enc = tiktoken.get_encoding("r50k_base") 858s 858s tests/test_encoding.py:74: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________________ test_encode_bytes _______________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_encode_bytes(): 858s > enc = tiktoken.get_encoding("cl100k_base") 858s 858s tests/test_encoding.py:79: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _________________________ test_encode_surrogate_pairs __________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_encode_surrogate_pairs(): 858s > enc = tiktoken.get_encoding("cl100k_base") 858s 858s tests/test_encoding.py:84: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _________________ test_catastrophically_repetitive[r50k_base] __________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:96: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ________________ test_catastrophically_repetitive[cl100k_base] _________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:96: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _______________________ test_basic_roundtrip[r50k_base] ________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_basic_roundtrip(make_enc): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:115: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________ test_basic_roundtrip[cl100k_base] _______________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_basic_roundtrip(make_enc): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:115: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ________________________ test_hyp_roundtrip[r50k_base] _________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s > @hypothesis.given(text=st.text()) 858s 858s tests/test_encoding.py:131: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s tests/test_encoding.py:134: in test_hyp_roundtrip 858s enc = make_enc() 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s E Falsifying example: test_hyp_roundtrip( 858s E make_enc=functools.partial(get_encoding, 'r50k_base'), 858s E text='', # or any other generated value 858s E ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _______________________ test_hyp_roundtrip[cl100k_base] ________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s > @hypothesis.given(text=st.text()) 858s 858s tests/test_encoding.py:131: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s tests/test_encoding.py:134: in test_hyp_roundtrip 858s enc = make_enc() 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s E Falsifying example: test_hyp_roundtrip( 858s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 858s E text='', # or any other generated value 858s E ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ____________________ test_single_token_roundtrip[r50k_base] ____________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:141: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ___________________ test_single_token_roundtrip[cl100k_base] ___________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:141: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ______________________________ test_special_token ______________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s E: pybuild pybuild:389: test: plugin pyproject failed with: exit code=1: cd /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build; python3.13 -m pytest tests 858s I: pybuild base:311: cd /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build; python3.12 -m pytest tests 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s def test_special_token(): 858s > enc = tiktoken.get_encoding("cl100k_base") 858s 858s tests/test_encoding.py:157: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _____________________ test_hyp_special_ordinary[r50k_base] _____________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s > @hypothesis.given(text=st.text()) 858s 858s tests/test_encoding.py:208: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s tests/test_encoding.py:211: in test_hyp_special_ordinary 858s enc = make_enc() 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s E Falsifying example: test_hyp_special_ordinary( 858s E make_enc=functools.partial(get_encoding, 'r50k_base'), 858s E text='', # or any other generated value 858s E ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ____________________ test_hyp_special_ordinary[cl100k_base] ____________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s > @hypothesis.given(text=st.text()) 858s 858s tests/test_encoding.py:208: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s tests/test_encoding.py:211: in test_hyp_special_ordinary 858s enc = make_enc() 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s E Falsifying example: test_hyp_special_ordinary( 858s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 858s E text='', # or any other generated value 858s E ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s _________________________ test_batch_encode[r50k_base] _________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'r50k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:222: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s except (ProtocolError, OSError) as err: 858s raise ConnectionError(err, request=request) 858s 858s except MaxRetryError as e: 858s if isinstance(e.reason, ConnectTimeoutError): 858s # TODO: Remove this in 3.0.0: see #2811 858s if not isinstance(e.reason, NewConnectionError): 858s raise ConnectTimeout(e, request=request) 858s 858s if isinstance(e.reason, ResponseError): 858s raise RetryError(e, request=request) 858s 858s if isinstance(e.reason, _ProxyError): 858s raise ProxyError(e, request=request) 858s 858s if isinstance(e.reason, _SSLError): 858s # This branch is for urllib3 v1.22 and later. 858s raise SSLError(e, request=request) 858s 858s > raise ConnectionError(e, request=request) 858s 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')) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 858s ________________________ test_batch_encode[cl100k_base] ________________________ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s > sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 858s raise err 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 858s source_address = None, socket_options = [(6, 1, 1)] 858s 858s def create_connection( 858s address: tuple[str, int], 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s source_address: tuple[str, int] | None = None, 858s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 858s ) -> socket.socket: 858s """Connect to *address* and return the socket object. 858s 858s Convenience function. Connect to *address* (a 2-tuple ``(host, 858s port)``) and return the socket object. Passing the optional 858s *timeout* parameter will set the timeout on the socket instance 858s before attempting to connect. If no *timeout* is supplied, the 858s global default timeout setting returned by :func:`socket.getdefaulttimeout` 858s is used. If *source_address* is set it must be a tuple of (host, port) 858s for the socket to bind as a source address before making the connection. 858s An host of '' or port 0 tells the OS to use the default. 858s """ 858s 858s host, port = address 858s if host.startswith("["): 858s host = host.strip("[]") 858s err = None 858s 858s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 858s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 858s # The original create_connection function always returns all records. 858s family = allowed_gai_family() 858s 858s try: 858s host.encode("idna") 858s except UnicodeError: 858s raise LocationParseError(f"'{host}', label empty or too long") from None 858s 858s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 858s af, socktype, proto, canonname, sa = res 858s sock = None 858s try: 858s sock = socket.socket(af, socktype, proto) 858s 858s # If provided, set socket level options before connecting. 858s _set_socket_options(sock, socket_options) 858s 858s if timeout is not _DEFAULT_TIMEOUT: 858s sock.settimeout(timeout) 858s if source_address: 858s sock.bind(source_address) 858s > sock.connect(sa) 858s E ConnectionRefusedError: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 858s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 858s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s redirect = False, assert_same_host = False 858s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 858s release_conn = False, chunked = False, body_pos = None, preload_content = False 858s decode_content = False, response_kw = {} 858s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 858s destination_scheme = None, conn = None, release_this_conn = True 858s http_tunnel_required = False, err = None, clean_exit = False 858s 858s def urlopen( # type: ignore[override] 858s self, 858s method: str, 858s url: str, 858s body: _TYPE_BODY | None = None, 858s headers: typing.Mapping[str, str] | None = None, 858s retries: Retry | bool | int | None = None, 858s redirect: bool = True, 858s assert_same_host: bool = True, 858s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 858s pool_timeout: int | None = None, 858s release_conn: bool | None = None, 858s chunked: bool = False, 858s body_pos: _TYPE_BODY_POSITION | None = None, 858s preload_content: bool = True, 858s decode_content: bool = True, 858s **response_kw: typing.Any, 858s ) -> BaseHTTPResponse: 858s """ 858s Get a connection from the pool and perform an HTTP request. This is the 858s lowest level call for making a request, so you'll need to specify all 858s the raw details. 858s 858s .. note:: 858s 858s More commonly, it's appropriate to use a convenience method 858s such as :meth:`request`. 858s 858s .. note:: 858s 858s `release_conn` will only behave as expected if 858s `preload_content=False` because we want to make 858s `preload_content=False` the default behaviour someday soon without 858s breaking backwards compatibility. 858s 858s :param method: 858s HTTP request method (such as GET, POST, PUT, etc.) 858s 858s :param url: 858s The URL to perform the request on. 858s 858s :param body: 858s Data to send in the request body, either :class:`str`, :class:`bytes`, 858s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 858s 858s :param headers: 858s Dictionary of custom headers to send, such as User-Agent, 858s If-None-Match, etc. If None, pool headers are used. If provided, 858s these headers completely replace any pool-specific headers. 858s 858s :param retries: 858s Configure the number of retries to allow before raising a 858s :class:`~urllib3.exceptions.MaxRetryError` exception. 858s 858s Pass ``None`` to retry until you receive a response. Pass a 858s :class:`~urllib3.util.retry.Retry` object for fine-grained control 858s over different types of retries. 858s Pass an integer number to retry connection errors that many times, 858s but no other types of errors. Pass zero to never retry. 858s 858s If ``False``, then retries are disabled and any exception is raised 858s immediately. Also, instead of raising a MaxRetryError on redirects, 858s the redirect response will be returned. 858s 858s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 858s 858s :param redirect: 858s If True, automatically handle redirects (status codes 301, 302, 858s 303, 307, 308). Each redirect counts as a retry. Disabling retries 858s will disable redirect, too. 858s 858s :param assert_same_host: 858s If ``True``, will make sure that the host of the pool requests is 858s consistent else will raise HostChangedError. When ``False``, you can 858s use the pool on an HTTP proxy and request foreign hosts. 858s 858s :param timeout: 858s If specified, overrides the default timeout for this one 858s request. It may be a float (in seconds) or an instance of 858s :class:`urllib3.util.Timeout`. 858s 858s :param pool_timeout: 858s If set and the pool is set to block=True, then this method will 858s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 858s connection is available within the time period. 858s 858s :param bool preload_content: 858s If True, the response's body will be preloaded into memory. 858s 858s :param bool decode_content: 858s If True, will attempt to decode the body based on the 858s 'content-encoding' header. 858s 858s :param release_conn: 858s If False, then the urlopen call will not release the connection 858s back into the pool once a response is received (but will release if 858s you read the entire contents of the response such as when 858s `preload_content=True`). This is useful if you're not preloading 858s the response's content immediately. You will need to call 858s ``r.release_conn()`` on the response ``r`` to return the connection 858s back into the pool. If None, it takes the value of ``preload_content`` 858s which defaults to ``True``. 858s 858s :param bool chunked: 858s If True, urllib3 will send the body using chunked transfer 858s encoding. Otherwise, urllib3 will send the body using the standard 858s content-length form. Defaults to False. 858s 858s :param int body_pos: 858s Position to seek to in file-like body in the event of a retry or 858s redirect. Typically this won't need to be set because urllib3 will 858s auto-populate the value when needed. 858s """ 858s parsed_url = parse_url(url) 858s destination_scheme = parsed_url.scheme 858s 858s if headers is None: 858s headers = self.headers 858s 858s if not isinstance(retries, Retry): 858s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 858s 858s if release_conn is None: 858s release_conn = preload_content 858s 858s # Check host 858s if assert_same_host and not self.is_same_host(url): 858s raise HostChangedError(self, url, retries) 858s 858s # Ensure that the URL we're connecting to is properly encoded 858s if url.startswith("/"): 858s url = to_str(_encode_target(url)) 858s else: 858s url = to_str(parsed_url.url) 858s 858s conn = None 858s 858s # Track whether `conn` needs to be released before 858s # returning/raising/recursing. Update this variable if necessary, and 858s # leave `release_conn` constant throughout the function. That way, if 858s # the function recurses, the original value of `release_conn` will be 858s # passed down into the recursive call, and its value will be respected. 858s # 858s # See issue #651 [1] for details. 858s # 858s # [1] 858s release_this_conn = release_conn 858s 858s http_tunnel_required = connection_requires_http_tunnel( 858s self.proxy, self.proxy_config, destination_scheme 858s ) 858s 858s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 858s # have to copy the headers dict so we can safely change it without those 858s # changes being reflected in anyone else's copy. 858s if not http_tunnel_required: 858s headers = headers.copy() # type: ignore[attr-defined] 858s headers.update(self.proxy_headers) # type: ignore[union-attr] 858s 858s # Must keep the exception bound to a separate variable or else Python 3 858s # complains about UnboundLocalError. 858s err = None 858s 858s # Keep track of whether we cleanly exited the except block. This 858s # ensures we do proper cleanup in finally. 858s clean_exit = False 858s 858s # Rewind body position, if needed. Record current position 858s # for future rewinds in the event of a redirect/retry. 858s body_pos = set_file_position(body, body_pos) 858s 858s try: 858s # Request a connection from the queue. 858s timeout_obj = self._get_timeout(timeout) 858s conn = self._get_conn(timeout=pool_timeout) 858s 858s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 858s 858s # Is this a closed/new connection that requires CONNECT tunnelling? 858s if self.proxy is not None and http_tunnel_required and conn.is_closed: 858s try: 858s self._prepare_proxy(conn) 858s except (BaseSSLError, OSError, SocketTimeout) as e: 858s self._raise_timeout( 858s err=e, url=self.proxy.url, timeout_value=conn.timeout 858s ) 858s raise 858s 858s # If we're going to release the connection in ``finally:``, then 858s # the response doesn't need to know about the connection. Otherwise 858s # it will also try to release it and we'll have a double-release 858s # mess. 858s response_conn = conn if not release_conn else None 858s 858s # Make the request on the HTTPConnection object 858s > response = self._make_request( 858s conn, 858s method, 858s url, 858s timeout=timeout_obj, 858s body=body, 858s headers=headers, 858s chunked=chunked, 858s retries=retries, 858s response_conn=response_conn, 858s preload_content=preload_content, 858s decode_content=decode_content, 858s **response_kw, 858s ) 858s 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 858s raise new_e 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 858s self._validate_conn(conn) 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 858s conn.connect() 858s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 858s self.sock = sock = self._new_conn() 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s 858s def _new_conn(self) -> socket.socket: 858s """Establish a socket connection and set nodelay settings on it. 858s 858s :return: New socket connection. 858s """ 858s try: 858s sock = connection.create_connection( 858s (self._dns_host, self.port), 858s self.timeout, 858s source_address=self.source_address, 858s socket_options=self.socket_options, 858s ) 858s except socket.gaierror as e: 858s raise NameResolutionError(self.host, self, e) from e 858s except SocketTimeout as e: 858s raise ConnectTimeoutError( 858s self, 858s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 858s ) from e 858s 858s except OSError as e: 858s > raise NewConnectionError( 858s self, f"Failed to establish a new connection: {e}" 858s ) from e 858s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 858s 858s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 858s 858s The above exception was the direct cause of the following exception: 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 858s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 858s ): 858s """Sends PreparedRequest object. Returns Response object. 858s 858s :param request: The :class:`PreparedRequest ` being sent. 858s :param stream: (optional) Whether to stream the request content. 858s :param timeout: (optional) How long to wait for the server to send 858s data before giving up, as a float, or a :ref:`(connect timeout, 858s read timeout) ` tuple. 858s :type timeout: float or tuple or urllib3 Timeout object 858s :param verify: (optional) Either a boolean, in which case it controls whether 858s we verify the server's TLS certificate, or a string, in which case it 858s must be a path to a CA bundle to use 858s :param cert: (optional) Any user-provided SSL certificate to be trusted. 858s :param proxies: (optional) The proxies dictionary to apply to the request. 858s :rtype: requests.Response 858s """ 858s 858s try: 858s conn = self.get_connection_with_tls_context( 858s request, verify, proxies=proxies, cert=cert 858s ) 858s except LocationValueError as e: 858s raise InvalidURL(e, request=request) 858s 858s self.cert_verify(conn, request.url, verify, cert) 858s url = self.request_url(request, proxies) 858s self.add_headers( 858s request, 858s stream=stream, 858s timeout=timeout, 858s verify=verify, 858s cert=cert, 858s proxies=proxies, 858s ) 858s 858s chunked = not (request.body is None or "Content-Length" in request.headers) 858s 858s if isinstance(timeout, tuple): 858s try: 858s connect, read = timeout 858s timeout = TimeoutSauce(connect=connect, read=read) 858s except ValueError: 858s raise ValueError( 858s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 858s f"or a single float to set both timeouts to the same value." 858s ) 858s elif isinstance(timeout, TimeoutSauce): 858s pass 858s else: 858s timeout = TimeoutSauce(connect=timeout, read=timeout) 858s 858s try: 858s > resp = conn.urlopen( 858s method=request.method, 858s url=url, 858s body=request.body, 858s headers=request.headers, 858s redirect=False, 858s assert_same_host=False, 858s preload_content=False, 858s decode_content=False, 858s retries=self.max_retries, 858s timeout=timeout, 858s chunked=chunked, 858s ) 858s 858s /usr/lib/python3/dist-packages/requests/adapters.py:667: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 858s retries = retries.increment( 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 858s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 858s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 858s _pool = 858s _stacktrace = 858s 858s def increment( 858s self, 858s method: str | None = None, 858s url: str | None = None, 858s response: BaseHTTPResponse | None = None, 858s error: Exception | None = None, 858s _pool: ConnectionPool | None = None, 858s _stacktrace: TracebackType | None = None, 858s ) -> Retry: 858s """Return a new Retry object with incremented retry counters. 858s 858s :param response: A response object, or None, if the server did not 858s return a response. 858s :type response: :class:`~urllib3.response.BaseHTTPResponse` 858s :param Exception error: An error encountered during the request, or 858s None if the response was received successfully. 858s 858s :return: A new ``Retry`` object. 858s """ 858s if self.total is False and error: 858s # Disabled, indicate to re-raise the error. 858s raise reraise(type(error), error, _stacktrace) 858s 858s total = self.total 858s if total is not None: 858s total -= 1 858s 858s connect = self.connect 858s read = self.read 858s redirect = self.redirect 858s status_count = self.status 858s other = self.other 858s cause = "unknown" 858s status = None 858s redirect_location = None 858s 858s if error and self._is_connection_error(error): 858s # Connect retry? 858s if connect is False: 858s raise reraise(type(error), error, _stacktrace) 858s elif connect is not None: 858s connect -= 1 858s 858s elif error and self._is_read_error(error): 858s # Read retry? 858s if read is False or method is None or not self._is_method_retryable(method): 858s raise reraise(type(error), error, _stacktrace) 858s elif read is not None: 858s read -= 1 858s 858s elif error: 858s # Other retry? 858s if other is not None: 858s other -= 1 858s 858s elif response and response.get_redirect_location(): 858s # Redirect retry? 858s if redirect is not None: 858s redirect -= 1 858s cause = "too many redirects" 858s response_redirect_location = response.get_redirect_location() 858s if response_redirect_location: 858s redirect_location = response_redirect_location 858s status = response.status 858s 858s else: 858s # Incrementing because of a server error like a 500 in 858s # status_forcelist and the given method is in the allowed_methods 858s cause = ResponseError.GENERIC_ERROR 858s if response and response.status: 858s if status_count is not None: 858s status_count -= 1 858s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 858s status = response.status 858s 858s history = self.history + ( 858s RequestHistory(method, url, error, status, redirect_location), 858s ) 858s 858s new_retry = self.new( 858s total=total, 858s connect=connect, 858s read=read, 858s redirect=redirect, 858s status=status_count, 858s other=other, 858s history=history, 858s ) 858s 858s if new_retry.is_exhausted(): 858s reason = error or ResponseError(cause) 858s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 858s 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')) 858s 858s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 858s 858s During handling of the above exception, another exception occurred: 858s 858s make_enc = functools.partial(, 'cl100k_base') 858s 858s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 858s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 858s > enc = make_enc() 858s 858s tests/test_encoding.py:222: 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 858s enc = Encoding(**constructor()) 858s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 858s mergeable_ranks = load_tiktoken_bpe( 858s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 858s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 858s contents = read_file(blobpath) 858s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 858s resp = requests.get(blobpath) 858s /usr/lib/python3/dist-packages/requests/api.py:73: in get 858s return request("get", url, params=params, **kwargs) 858s /usr/lib/python3/dist-packages/requests/api.py:59: in request 858s return session.request(method=method, url=url, **kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 858s resp = self.send(prep, **send_kwargs) 858s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 858s r = adapter.send(request, **kwargs) 858s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 858s 858s self = 858s request = , stream = False 858s timeout = Timeout(connect=None, read=None, total=None), verify = True 858s cert = None, proxies = OrderedDict() 858s 858s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s _____________________ test_hyp_batch_roundtrip[r50k_base] ______________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s make_enc = functools.partial(, 'r50k_base') 859s 859s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 859s > @hypothesis.given(batch=st.lists(st.text())) 859s 859s tests/test_encoding.py:237: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 859s enc = make_enc() 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 859s mergeable_ranks = load_tiktoken_bpe( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 859s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s E Falsifying example: test_hyp_batch_roundtrip( 859s E make_enc=functools.partial(get_encoding, 'r50k_base'), 859s E batch=[], # or any other generated value 859s E ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s ____________________ test_hyp_batch_roundtrip[cl100k_base] _____________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s make_enc = functools.partial(, 'cl100k_base') 859s 859s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 859s > @hypothesis.given(batch=st.lists(st.text())) 859s 859s tests/test_encoding.py:237: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 859s enc = make_enc() 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 859s mergeable_ranks = load_tiktoken_bpe( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 859s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s E Falsifying example: test_hyp_batch_roundtrip( 859s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 859s E batch=[], # or any other generated value 859s E ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s ___________________________ test_encoding_for_model ____________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s def test_encoding_for_model(): 859s > enc = tiktoken.encoding_for_model("gpt2") 859s 859s tests/test_misc.py:8: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 859s return get_encoding(encoding_name_for_model(model_name)) 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 859s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 859s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s ________________________ test_hyp_offsets[cl100k_base] _________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s make_enc = functools.partial(, 'cl100k_base') 859s 859s @pytest.mark.parametrize("make_enc", SOME_ENCODING_FACTORIES) 859s > @hypothesis.given(data=st.data()) 859s 859s tests/test_offsets.py:29: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s tests/test_offsets.py:32: in test_hyp_offsets 859s enc = make_enc() 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 859s mergeable_ranks = load_tiktoken_bpe( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 859s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s E Falsifying example: test_hyp_offsets( 859s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 859s E data=data(...), 859s E ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s ______________________________ test_basic_offsets ______________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s def test_basic_offsets(): 859s > enc = tiktoken.get_encoding("cl100k_base") 859s 859s tests/test_offsets.py:50: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 859s mergeable_ranks = load_tiktoken_bpe( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 859s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s _________________________________ test_pickle __________________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s def test_pickle(): 859s import pickle 859s 859s > enc_old = tiktoken.get_encoding("r50k_base") 859s 859s tests/test_pickle.py:7: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 859s mergeable_ranks = load_tiktoken_bpe( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 859s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s _________________________________ test_simple __________________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s def test_simple(): 859s # Note that there are more actual tests, they're just not currently public :-) 859s > enc = tiktoken.get_encoding("gpt2") 859s 859s tests/test_simple_public.py:9: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 859s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 859s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s ___________________________ test_encoding_for_model ____________________________ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s > sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 859s raise err 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 859s source_address = None, socket_options = [(6, 1, 1)] 859s 859s def create_connection( 859s address: tuple[str, int], 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s source_address: tuple[str, int] | None = None, 859s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 859s ) -> socket.socket: 859s """Connect to *address* and return the socket object. 859s 859s Convenience function. Connect to *address* (a 2-tuple ``(host, 859s port)``) and return the socket object. Passing the optional 859s *timeout* parameter will set the timeout on the socket instance 859s before attempting to connect. If no *timeout* is supplied, the 859s global default timeout setting returned by :func:`socket.getdefaulttimeout` 859s is used. If *source_address* is set it must be a tuple of (host, port) 859s for the socket to bind as a source address before making the connection. 859s An host of '' or port 0 tells the OS to use the default. 859s """ 859s 859s host, port = address 859s if host.startswith("["): 859s host = host.strip("[]") 859s err = None 859s 859s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 859s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 859s # The original create_connection function always returns all records. 859s family = allowed_gai_family() 859s 859s try: 859s host.encode("idna") 859s except UnicodeError: 859s raise LocationParseError(f"'{host}', label empty or too long") from None 859s 859s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 859s af, socktype, proto, canonname, sa = res 859s sock = None 859s try: 859s sock = socket.socket(af, socktype, proto) 859s 859s # If provided, set socket level options before connecting. 859s _set_socket_options(sock, socket_options) 859s 859s if timeout is not _DEFAULT_TIMEOUT: 859s sock.settimeout(timeout) 859s if source_address: 859s sock.bind(source_address) 859s > sock.connect(sa) 859s E ConnectionRefusedError: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 859s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 859s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s redirect = False, assert_same_host = False 859s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 859s release_conn = False, chunked = False, body_pos = None, preload_content = False 859s decode_content = False, response_kw = {} 859s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 859s destination_scheme = None, conn = None, release_this_conn = True 859s http_tunnel_required = False, err = None, clean_exit = False 859s 859s def urlopen( # type: ignore[override] 859s self, 859s method: str, 859s url: str, 859s body: _TYPE_BODY | None = None, 859s headers: typing.Mapping[str, str] | None = None, 859s retries: Retry | bool | int | None = None, 859s redirect: bool = True, 859s assert_same_host: bool = True, 859s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 859s pool_timeout: int | None = None, 859s release_conn: bool | None = None, 859s chunked: bool = False, 859s body_pos: _TYPE_BODY_POSITION | None = None, 859s preload_content: bool = True, 859s decode_content: bool = True, 859s **response_kw: typing.Any, 859s ) -> BaseHTTPResponse: 859s """ 859s Get a connection from the pool and perform an HTTP request. This is the 859s lowest level call for making a request, so you'll need to specify all 859s the raw details. 859s 859s .. note:: 859s 859s More commonly, it's appropriate to use a convenience method 859s such as :meth:`request`. 859s 859s .. note:: 859s 859s `release_conn` will only behave as expected if 859s `preload_content=False` because we want to make 859s `preload_content=False` the default behaviour someday soon without 859s breaking backwards compatibility. 859s 859s :param method: 859s HTTP request method (such as GET, POST, PUT, etc.) 859s 859s :param url: 859s The URL to perform the request on. 859s 859s :param body: 859s Data to send in the request body, either :class:`str`, :class:`bytes`, 859s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 859s 859s :param headers: 859s Dictionary of custom headers to send, such as User-Agent, 859s If-None-Match, etc. If None, pool headers are used. If provided, 859s these headers completely replace any pool-specific headers. 859s 859s :param retries: 859s Configure the number of retries to allow before raising a 859s :class:`~urllib3.exceptions.MaxRetryError` exception. 859s 859s Pass ``None`` to retry until you receive a response. Pass a 859s :class:`~urllib3.util.retry.Retry` object for fine-grained control 859s over different types of retries. 859s Pass an integer number to retry connection errors that many times, 859s but no other types of errors. Pass zero to never retry. 859s 859s If ``False``, then retries are disabled and any exception is raised 859s immediately. Also, instead of raising a MaxRetryError on redirects, 859s the redirect response will be returned. 859s 859s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 859s 859s :param redirect: 859s If True, automatically handle redirects (status codes 301, 302, 859s 303, 307, 308). Each redirect counts as a retry. Disabling retries 859s will disable redirect, too. 859s 859s :param assert_same_host: 859s If ``True``, will make sure that the host of the pool requests is 859s consistent else will raise HostChangedError. When ``False``, you can 859s use the pool on an HTTP proxy and request foreign hosts. 859s 859s :param timeout: 859s If specified, overrides the default timeout for this one 859s request. It may be a float (in seconds) or an instance of 859s :class:`urllib3.util.Timeout`. 859s 859s :param pool_timeout: 859s If set and the pool is set to block=True, then this method will 859s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 859s connection is available within the time period. 859s 859s :param bool preload_content: 859s If True, the response's body will be preloaded into memory. 859s 859s :param bool decode_content: 859s If True, will attempt to decode the body based on the 859s 'content-encoding' header. 859s 859s :param release_conn: 859s If False, then the urlopen call will not release the connection 859s back into the pool once a response is received (but will release if 859s you read the entire contents of the response such as when 859s `preload_content=True`). This is useful if you're not preloading 859s the response's content immediately. You will need to call 859s ``r.release_conn()`` on the response ``r`` to return the connection 859s back into the pool. If None, it takes the value of ``preload_content`` 859s which defaults to ``True``. 859s 859s :param bool chunked: 859s If True, urllib3 will send the body using chunked transfer 859s encoding. Otherwise, urllib3 will send the body using the standard 859s content-length form. Defaults to False. 859s 859s :param int body_pos: 859s Position to seek to in file-like body in the event of a retry or 859s redirect. Typically this won't need to be set because urllib3 will 859s auto-populate the value when needed. 859s """ 859s parsed_url = parse_url(url) 859s destination_scheme = parsed_url.scheme 859s 859s if headers is None: 859s headers = self.headers 859s 859s if not isinstance(retries, Retry): 859s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 859s 859s if release_conn is None: 859s release_conn = preload_content 859s 859s # Check host 859s if assert_same_host and not self.is_same_host(url): 859s raise HostChangedError(self, url, retries) 859s 859s # Ensure that the URL we're connecting to is properly encoded 859s if url.startswith("/"): 859s url = to_str(_encode_target(url)) 859s else: 859s url = to_str(parsed_url.url) 859s 859s conn = None 859s 859s # Track whether `conn` needs to be released before 859s # returning/raising/recursing. Update this variable if necessary, and 859s # leave `release_conn` constant throughout the function. That way, if 859s # the function recurses, the original value of `release_conn` will be 859s # passed down into the recursive call, and its value will be respected. 859s # 859s # See issue #651 [1] for details. 859s # 859s # [1] 859s release_this_conn = release_conn 859s 859s http_tunnel_required = connection_requires_http_tunnel( 859s self.proxy, self.proxy_config, destination_scheme 859s ) 859s 859s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 859s # have to copy the headers dict so we can safely change it without those 859s # changes being reflected in anyone else's copy. 859s if not http_tunnel_required: 859s headers = headers.copy() # type: ignore[attr-defined] 859s headers.update(self.proxy_headers) # type: ignore[union-attr] 859s 859s # Must keep the exception bound to a separate variable or else Python 3 859s # complains about UnboundLocalError. 859s err = None 859s 859s # Keep track of whether we cleanly exited the except block. This 859s # ensures we do proper cleanup in finally. 859s clean_exit = False 859s 859s # Rewind body position, if needed. Record current position 859s # for future rewinds in the event of a redirect/retry. 859s body_pos = set_file_position(body, body_pos) 859s 859s try: 859s # Request a connection from the queue. 859s timeout_obj = self._get_timeout(timeout) 859s conn = self._get_conn(timeout=pool_timeout) 859s 859s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 859s 859s # Is this a closed/new connection that requires CONNECT tunnelling? 859s if self.proxy is not None and http_tunnel_required and conn.is_closed: 859s try: 859s self._prepare_proxy(conn) 859s except (BaseSSLError, OSError, SocketTimeout) as e: 859s self._raise_timeout( 859s err=e, url=self.proxy.url, timeout_value=conn.timeout 859s ) 859s raise 859s 859s # If we're going to release the connection in ``finally:``, then 859s # the response doesn't need to know about the connection. Otherwise 859s # it will also try to release it and we'll have a double-release 859s # mess. 859s response_conn = conn if not release_conn else None 859s 859s # Make the request on the HTTPConnection object 859s > response = self._make_request( 859s conn, 859s method, 859s url, 859s timeout=timeout_obj, 859s body=body, 859s headers=headers, 859s chunked=chunked, 859s retries=retries, 859s response_conn=response_conn, 859s preload_content=preload_content, 859s decode_content=decode_content, 859s **response_kw, 859s ) 859s 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 859s raise new_e 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 859s self._validate_conn(conn) 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 859s conn.connect() 859s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 859s self.sock = sock = self._new_conn() 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s 859s def _new_conn(self) -> socket.socket: 859s """Establish a socket connection and set nodelay settings on it. 859s 859s :return: New socket connection. 859s """ 859s try: 859s sock = connection.create_connection( 859s (self._dns_host, self.port), 859s self.timeout, 859s source_address=self.source_address, 859s socket_options=self.socket_options, 859s ) 859s except socket.gaierror as e: 859s raise NameResolutionError(self.host, self, e) from e 859s except SocketTimeout as e: 859s raise ConnectTimeoutError( 859s self, 859s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 859s ) from e 859s 859s except OSError as e: 859s > raise NewConnectionError( 859s self, f"Failed to establish a new connection: {e}" 859s ) from e 859s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 859s 859s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 859s 859s The above exception was the direct cause of the following exception: 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s > resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:667: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 859s retries = retries.increment( 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 859s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 859s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 859s _pool = 859s _stacktrace = 859s 859s def increment( 859s self, 859s method: str | None = None, 859s url: str | None = None, 859s response: BaseHTTPResponse | None = None, 859s error: Exception | None = None, 859s _pool: ConnectionPool | None = None, 859s _stacktrace: TracebackType | None = None, 859s ) -> Retry: 859s """Return a new Retry object with incremented retry counters. 859s 859s :param response: A response object, or None, if the server did not 859s return a response. 859s :type response: :class:`~urllib3.response.BaseHTTPResponse` 859s :param Exception error: An error encountered during the request, or 859s None if the response was received successfully. 859s 859s :return: A new ``Retry`` object. 859s """ 859s if self.total is False and error: 859s # Disabled, indicate to re-raise the error. 859s raise reraise(type(error), error, _stacktrace) 859s 859s total = self.total 859s if total is not None: 859s total -= 1 859s 859s connect = self.connect 859s read = self.read 859s redirect = self.redirect 859s status_count = self.status 859s other = self.other 859s cause = "unknown" 859s status = None 859s redirect_location = None 859s 859s if error and self._is_connection_error(error): 859s # Connect retry? 859s if connect is False: 859s raise reraise(type(error), error, _stacktrace) 859s elif connect is not None: 859s connect -= 1 859s 859s elif error and self._is_read_error(error): 859s # Read retry? 859s if read is False or method is None or not self._is_method_retryable(method): 859s raise reraise(type(error), error, _stacktrace) 859s elif read is not None: 859s read -= 1 859s 859s elif error: 859s # Other retry? 859s if other is not None: 859s other -= 1 859s 859s elif response and response.get_redirect_location(): 859s # Redirect retry? 859s if redirect is not None: 859s redirect -= 1 859s cause = "too many redirects" 859s response_redirect_location = response.get_redirect_location() 859s if response_redirect_location: 859s redirect_location = response_redirect_location 859s status = response.status 859s 859s else: 859s # Incrementing because of a server error like a 500 in 859s # status_forcelist and the given method is in the allowed_methods 859s cause = ResponseError.GENERIC_ERROR 859s if response and response.status: 859s if status_count is not None: 859s status_count -= 1 859s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 859s status = response.status 859s 859s history = self.history + ( 859s RequestHistory(method, url, error, status, redirect_location), 859s ) 859s 859s new_retry = self.new( 859s total=total, 859s connect=connect, 859s read=read, 859s redirect=redirect, 859s status=status_count, 859s other=other, 859s history=history, 859s ) 859s 859s if new_retry.is_exhausted(): 859s reason = error or ResponseError(cause) 859s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 859s 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')) 859s 859s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 859s 859s During handling of the above exception, another exception occurred: 859s 859s def test_encoding_for_model(): 859s > enc = tiktoken.encoding_for_model("gpt2") 859s 859s tests/test_simple_public.py:26: 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 859s return get_encoding(encoding_name_for_model(model_name)) 859s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 859s enc = Encoding(**constructor()) 859s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 859s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 859s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 859s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 859s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 859s contents = read_file(blobpath) 859s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 859s resp = requests.get(blobpath) 859s /usr/lib/python3/dist-packages/requests/api.py:73: in get 859s return request("get", url, params=params, **kwargs) 859s /usr/lib/python3/dist-packages/requests/api.py:59: in request 859s return session.request(method=method, url=url, **kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 859s resp = self.send(prep, **send_kwargs) 859s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 859s r = adapter.send(request, **kwargs) 859s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 859s 859s self = 859s request = , stream = False 859s timeout = Timeout(connect=None, read=None, total=None), verify = True 859s cert = None, proxies = OrderedDict() 859s 859s def send( 859s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 859s ): 859s """Sends PreparedRequest object. Returns Response object. 859s 859s :param request: The :class:`PreparedRequest ` being sent. 859s :param stream: (optional) Whether to stream the request content. 859s :param timeout: (optional) How long to wait for the server to send 859s data before giving up, as a float, or a :ref:`(connect timeout, 859s read timeout) ` tuple. 859s :type timeout: float or tuple or urllib3 Timeout object 859s :param verify: (optional) Either a boolean, in which case it controls whether 859s we verify the server's TLS certificate, or a string, in which case it 859s must be a path to a CA bundle to use 859s :param cert: (optional) Any user-provided SSL certificate to be trusted. 859s :param proxies: (optional) The proxies dictionary to apply to the request. 859s :rtype: requests.Response 859s """ 859s 859s try: 859s conn = self.get_connection_with_tls_context( 859s request, verify, proxies=proxies, cert=cert 859s ) 859s except LocationValueError as e: 859s raise InvalidURL(e, request=request) 859s 859s self.cert_verify(conn, request.url, verify, cert) 859s url = self.request_url(request, proxies) 859s self.add_headers( 859s request, 859s stream=stream, 859s timeout=timeout, 859s verify=verify, 859s cert=cert, 859s proxies=proxies, 859s ) 859s 859s chunked = not (request.body is None or "Content-Length" in request.headers) 859s 859s if isinstance(timeout, tuple): 859s try: 859s connect, read = timeout 859s timeout = TimeoutSauce(connect=connect, read=read) 859s except ValueError: 859s raise ValueError( 859s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 859s f"or a single float to set both timeouts to the same value." 859s ) 859s elif isinstance(timeout, TimeoutSauce): 859s pass 859s else: 859s timeout = TimeoutSauce(connect=timeout, read=timeout) 859s 859s try: 859s resp = conn.urlopen( 859s method=request.method, 859s url=url, 859s body=request.body, 859s headers=request.headers, 859s redirect=False, 859s assert_same_host=False, 859s preload_content=False, 859s decode_content=False, 859s retries=self.max_retries, 859s timeout=timeout, 859s chunked=chunked, 859s ) 859s 859s except (ProtocolError, OSError) as err: 859s raise ConnectionError(err, request=request) 859s 859s except MaxRetryError as e: 859s if isinstance(e.reason, ConnectTimeoutError): 859s # TODO: Remove this in 3.0.0: see #2811 859s if not isinstance(e.reason, NewConnectionError): 859s raise ConnectTimeout(e, request=request) 859s 859s if isinstance(e.reason, ResponseError): 859s raise RetryError(e, request=request) 859s 859s if isinstance(e.reason, _ProxyError): 859s raise ProxyError(e, request=request) 859s 859s if isinstance(e.reason, _SSLError): 859s # This branch is for urllib3 v1.22 and later. 859s raise SSLError(e, request=request) 859s 859s > raise ConnectionError(e, request=request) 859s 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')) 859s 859s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 859s =========================== short test summary info ============================ 859s FAILED tests/test_encoding.py::test_simple - requests.exceptions.ConnectionEr... 859s FAILED tests/test_encoding.py::test_simple_repeated - requests.exceptions.Con... 859s FAILED tests/test_encoding.py::test_simple_regex - requests.exceptions.Connec... 859s FAILED tests/test_encoding.py::test_basic_encode - requests.exceptions.Connec... 859s FAILED tests/test_encoding.py::test_encode_empty - requests.exceptions.Connec... 859s FAILED tests/test_encoding.py::test_encode_bytes - requests.exceptions.Connec... 859s FAILED tests/test_encoding.py::test_encode_surrogate_pairs - requests.excepti... 859s FAILED tests/test_encoding.py::test_catastrophically_repetitive[r50k_base] - ... 859s FAILED tests/test_encoding.py::test_catastrophically_repetitive[cl100k_base] 859s FAILED tests/test_encoding.py::test_basic_roundtrip[r50k_base] - requests.exc... 859s FAILED tests/test_encoding.py::test_basic_roundtrip[cl100k_base] - requests.e... 859s FAILED tests/test_encoding.py::test_hyp_roundtrip[r50k_base] - requests.excep... 859s FAILED tests/test_encoding.py::test_hyp_roundtrip[cl100k_base] - requests.exc... 859s FAILED tests/test_encoding.py::test_single_token_roundtrip[r50k_base] - reque... 859s FAILED tests/test_encoding.py::test_single_token_roundtrip[cl100k_base] - req... 859s FAILED tests/test_encoding.py::test_special_token - requests.exceptions.Conne... 859s FAILED tests/test_encoding.py::test_hyp_special_ordinary[r50k_base] - request... 859s FAILED tests/test_encoding.py::test_hyp_special_ordinary[cl100k_base] - reque... 859s FAILED tests/test_encoding.py::test_batch_encode[r50k_base] - requests.except... 859s FAILED tests/test_encoding.py::test_batch_encode[cl100k_base] - requests.exce... 859s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[r50k_base] - requests... 859s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[cl100k_base] - reques... 859s FAILED tests/test_misc.py::test_encoding_for_model - requests.exceptions.Conn... 859s FAILED tests/test_offsets.py::test_hyp_offsets[cl100k_base] - requests.except... 859s FAILED tests/test_offsets.py::test_basic_offsets - requests.exceptions.Connec... 859s FAILED tests/test_pickle.py::test_pickle - requests.exceptions.ConnectionErro... 859s FAILED tests/test_simple_public.py::test_simple - requests.exceptions.Connect... 859s FAILED tests/test_simple_public.py::test_encoding_for_model - requests.except... 859s =================== 28 failed, 2 passed in 606.99s (0:10:06) =================== 859s ============================= test session starts ============================== 859s platform linux -- Python 3.12.7, pytest-8.3.3, pluggy-1.5.0 859s rootdir: /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build 859s configfile: pyproject.toml 859s plugins: typeguard-4.4.1, hypothesis-6.119.3 859s collected 30 items 859s 885s tests/test_encoding.py FFFFFFFFFFFFFFFFFFFFFF [ 73%] 887s tests/test_misc.py F. [ 80%] 889s tests/test_offsets.py FF [ 86%] 890s tests/test_pickle.py F [ 90%] 893s tests/test_simple_public.py FF. [100%] 893s 893s =================================== FAILURES =================================== 893s _________________________________ test_simple __________________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_simple(): 893s > enc = tiktoken.get_encoding("gpt2") 893s 893s tests/test_encoding.py:15: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 893s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 893s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _____________________________ test_simple_repeated _____________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_simple_repeated(): 893s > enc = tiktoken.get_encoding("gpt2") 893s 893s tests/test_encoding.py:32: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 893s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 893s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_simple_regex _______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_simple_regex(): 893s > enc = tiktoken.get_encoding("cl100k_base") 893s 893s tests/test_encoding.py:53: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_basic_encode _______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_basic_encode(): 893s > enc = tiktoken.get_encoding("r50k_base") 893s 893s tests/test_encoding.py:62: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_encode_empty _______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_encode_empty(): 893s > enc = tiktoken.get_encoding("r50k_base") 893s 893s tests/test_encoding.py:74: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_encode_bytes _______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_encode_bytes(): 893s > enc = tiktoken.get_encoding("cl100k_base") 893s 893s tests/test_encoding.py:79: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _________________________ test_encode_surrogate_pairs __________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_encode_surrogate_pairs(): 893s > enc = tiktoken.get_encoding("cl100k_base") 893s 893s tests/test_encoding.py:84: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _________________ test_catastrophically_repetitive[r50k_base] __________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:96: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ________________ test_catastrophically_repetitive[cl100k_base] _________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_catastrophically_repetitive(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:96: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _______________________ test_basic_roundtrip[r50k_base] ________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_basic_roundtrip(make_enc): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:115: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________ test_basic_roundtrip[cl100k_base] _______________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_basic_roundtrip(make_enc): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:115: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ________________________ test_hyp_roundtrip[r50k_base] _________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(text=st.text()) 893s 893s tests/test_encoding.py:131: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:134: in test_hyp_roundtrip 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_roundtrip( 893s E make_enc=functools.partial(get_encoding, 'r50k_base'), 893s E text='', 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _______________________ test_hyp_roundtrip[cl100k_base] ________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(text=st.text()) 893s 893s tests/test_encoding.py:131: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:134: in test_hyp_roundtrip 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_roundtrip( 893s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 893s E text='', 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ____________________ test_single_token_roundtrip[r50k_base] ____________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=responE: pybuild pybuild:389: test: plugin pyproject failed with: exit code=1: cd /tmp/autopkgtest.kUcq3X/autopkgtest_tmp/build; python3.12 -m pytest tests 893s pybuild-autopkgtest: error: pybuild --autopkgtest --test-pytest -i python{version} -p "3.13 3.12" returned exit code 13 893s se.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:141: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ___________________ test_single_token_roundtrip[cl100k_base] ___________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_single_token_roundtrip(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:141: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_special_token ______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_special_token(): 893s > enc = tiktoken.get_encoding("cl100k_base") 893s 893s tests/test_encoding.py:157: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _____________________ test_hyp_special_ordinary[r50k_base] _____________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(text=st.text()) 893s 893s tests/test_encoding.py:208: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:211: in test_hyp_special_ordinary 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_special_ordinary( 893s E make_enc=functools.partial(get_encoding, 'r50k_base'), 893s E text='', 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ____________________ test_hyp_special_ordinary[cl100k_base] ____________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is Falmake: *** [/tmp/WflFJTELKL/run:4: pybuild-autopkgtest] Error 25 893s se and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(text=st.text()) 893s 893s tests/test_encoding.py:208: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:211: in test_hyp_special_ordinary 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_special_ordinary( 893s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 893s E text='', 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _________________________ test_batch_encode[r50k_base] _________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:222: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ________________________ test_batch_encode[cl100k_base] ________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s pybuild-autopkgtest: error: /tmp/WflFJTELKL/run pybuild-autopkgtest returned exit code 2 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s def test_batch_encode(make_enc: Callable[[], tiktoken.Encoding]): 893s > enc = make_enc() 893s 893s tests/test_encoding.py:222: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _____________________ test_hyp_batch_roundtrip[r50k_base] ______________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'r50k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(batch=st.lists(st.text())) 893s 893s tests/test_encoding.py:237: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_batch_roundtrip( 893s E make_enc=functools.partial(get_encoding, 'r50k_base'), 893s E batch=[], 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ____________________ test_hyp_batch_roundtrip[cl100k_base] _____________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", ENCODING_FACTORIES) 893s > @hypothesis.given(batch=st.lists(st.text())) 893s 893s tests/test_encoding.py:237: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_encoding.py:240: in test_hyp_batch_roundtrip 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_batch_roundtrip( 893s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 893s E batch=[], 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ___________________________ test_encoding_for_model ____________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_encoding_for_model(): 893s > enc = tiktoken.encoding_for_model("gpt2") 893s 893s tests/test_misc.py:8: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 893s return get_encoding(encoding_name_for_model(model_name)) 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 893s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 893s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ________________________ test_hyp_offsets[cl100k_base] _________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s make_enc = functools.partial(, 'cl100k_base') 893s 893s @pytest.mark.parametrize("make_enc", SOME_ENCODING_FACTORIES) 893s > @hypothesis.given(data=st.data()) 893s 893s tests/test_offsets.py:29: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s tests/test_offsets.py:32: in test_hyp_offsets 893s enc = make_enc() 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s E Falsifying example: test_hyp_offsets( 893s E make_enc=functools.partial(get_encoding, 'cl100k_base'), 893s E data=data(...), 893s E ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ______________________________ test_basic_offsets ______________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/cl100k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/cl100k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_basic_offsets(): 893s > enc = tiktoken.get_encoding("cl100k_base") 893s 893s tests/test_offsets.py:50: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:76: in cl100k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _________________________________ test_pickle __________________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/encodings/r50k_base.tiktoken', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/encodings/r50k_base.tiktoken', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_pickle(): 893s import pickle 893s 893s > enc_old = tiktoken.get_encoding("r50k_base") 893s 893s tests/test_pickle.py:7: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:34: in r50k_base 893s mergeable_ranks = load_tiktoken_bpe( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:144: in load_tiktoken_bpe 893s contents = read_file_cached(tiktoken_bpe_file, expected_hash) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s _________________________________ test_simple __________________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_simple(): 893s # Note that there are more actual tests, they're just not currently public :-) 893s > enc = tiktoken.get_encoding("gpt2") 893s 893s tests/test_simple_public.py:9: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 893s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 893s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s ___________________________ test_encoding_for_model ____________________________ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s > sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:203: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:85: in create_connection 893s raise err 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s address = ('openaipublic.blob.core.windows.net', 443), timeout = None 893s source_address = None, socket_options = [(6, 1, 1)] 893s 893s def create_connection( 893s address: tuple[str, int], 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s source_address: tuple[str, int] | None = None, 893s socket_options: _TYPE_SOCKET_OPTIONS | None = None, 893s ) -> socket.socket: 893s """Connect to *address* and return the socket object. 893s 893s Convenience function. Connect to *address* (a 2-tuple ``(host, 893s port)``) and return the socket object. Passing the optional 893s *timeout* parameter will set the timeout on the socket instance 893s before attempting to connect. If no *timeout* is supplied, the 893s global default timeout setting returned by :func:`socket.getdefaulttimeout` 893s is used. If *source_address* is set it must be a tuple of (host, port) 893s for the socket to bind as a source address before making the connection. 893s An host of '' or port 0 tells the OS to use the default. 893s """ 893s 893s host, port = address 893s if host.startswith("["): 893s host = host.strip("[]") 893s err = None 893s 893s # Using the value from allowed_gai_family() in the context of getaddrinfo lets 893s # us select whether to work with IPv4 DNS records, IPv6 records, or both. 893s # The original create_connection function always returns all records. 893s family = allowed_gai_family() 893s 893s try: 893s host.encode("idna") 893s except UnicodeError: 893s raise LocationParseError(f"'{host}', label empty or too long") from None 893s 893s for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): 893s af, socktype, proto, canonname, sa = res 893s sock = None 893s try: 893s sock = socket.socket(af, socktype, proto) 893s 893s # If provided, set socket level options before connecting. 893s _set_socket_options(sock, socket_options) 893s 893s if timeout is not _DEFAULT_TIMEOUT: 893s sock.settimeout(timeout) 893s if source_address: 893s sock.bind(source_address) 893s > sock.connect(sa) 893s E ConnectionRefusedError: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/util/connection.py:73: ConnectionRefusedError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', body = None 893s headers = {'User-Agent': 'python-requests/2.32.3', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'} 893s retries = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s redirect = False, assert_same_host = False 893s timeout = Timeout(connect=None, read=None, total=None), pool_timeout = None 893s release_conn = False, chunked = False, body_pos = None, preload_content = False 893s decode_content = False, response_kw = {} 893s parsed_url = Url(scheme=None, auth=None, host=None, port=None, path='/gpt-2/encodings/main/vocab.bpe', query=None, fragment=None) 893s destination_scheme = None, conn = None, release_this_conn = True 893s http_tunnel_required = False, err = None, clean_exit = False 893s 893s def urlopen( # type: ignore[override] 893s self, 893s method: str, 893s url: str, 893s body: _TYPE_BODY | None = None, 893s headers: typing.Mapping[str, str] | None = None, 893s retries: Retry | bool | int | None = None, 893s redirect: bool = True, 893s assert_same_host: bool = True, 893s timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, 893s pool_timeout: int | None = None, 893s release_conn: bool | None = None, 893s chunked: bool = False, 893s body_pos: _TYPE_BODY_POSITION | None = None, 893s preload_content: bool = True, 893s decode_content: bool = True, 893s **response_kw: typing.Any, 893s ) -> BaseHTTPResponse: 893s """ 893s Get a connection from the pool and perform an HTTP request. This is the 893s lowest level call for making a request, so you'll need to specify all 893s the raw details. 893s 893s .. note:: 893s 893s More commonly, it's appropriate to use a convenience method 893s such as :meth:`request`. 893s 893s .. note:: 893s 893s `release_conn` will only behave as expected if 893s `preload_content=False` because we want to make 893s `preload_content=False` the default behaviour someday soon without 893s breaking backwards compatibility. 893s 893s :param method: 893s HTTP request method (such as GET, POST, PUT, etc.) 893s 893s :param url: 893s The URL to perform the request on. 893s 893s :param body: 893s Data to send in the request body, either :class:`str`, :class:`bytes`, 893s an iterable of :class:`str`/:class:`bytes`, or a file-like object. 893s 893s :param headers: 893s Dictionary of custom headers to send, such as User-Agent, 893s If-None-Match, etc. If None, pool headers are used. If provided, 893s these headers completely replace any pool-specific headers. 893s 893s :param retries: 893s Configure the number of retries to allow before raising a 893s :class:`~urllib3.exceptions.MaxRetryError` exception. 893s 893s Pass ``None`` to retry until you receive a response. Pass a 893s :class:`~urllib3.util.retry.Retry` object for fine-grained control 893s over different types of retries. 893s Pass an integer number to retry connection errors that many times, 893s but no other types of errors. Pass zero to never retry. 893s 893s If ``False``, then retries are disabled and any exception is raised 893s immediately. Also, instead of raising a MaxRetryError on redirects, 893s the redirect response will be returned. 893s 893s :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int. 893s 893s :param redirect: 893s If True, automatically handle redirects (status codes 301, 302, 893s 303, 307, 308). Each redirect counts as a retry. Disabling retries 893s will disable redirect, too. 893s 893s :param assert_same_host: 893s If ``True``, will make sure that the host of the pool requests is 893s consistent else will raise HostChangedError. When ``False``, you can 893s use the pool on an HTTP proxy and request foreign hosts. 893s 893s :param timeout: 893s If specified, overrides the default timeout for this one 893s request. It may be a float (in seconds) or an instance of 893s :class:`urllib3.util.Timeout`. 893s 893s :param pool_timeout: 893s If set and the pool is set to block=True, then this method will 893s block for ``pool_timeout`` seconds and raise EmptyPoolError if no 893s connection is available within the time period. 893s 893s :param bool preload_content: 893s If True, the response's body will be preloaded into memory. 893s 893s :param bool decode_content: 893s If True, will attempt to decode the body based on the 893s 'content-encoding' header. 893s 893s :param release_conn: 893s If False, then the urlopen call will not release the connection 893s back into the pool once a response is received (but will release if 893s you read the entire contents of the response such as when 893s `preload_content=True`). This is useful if you're not preloading 893s the response's content immediately. You will need to call 893s ``r.release_conn()`` on the response ``r`` to return the connection 893s back into the pool. If None, it takes the value of ``preload_content`` 893s which defaults to ``True``. 893s 893s :param bool chunked: 893s If True, urllib3 will send the body using chunked transfer 893s encoding. Otherwise, urllib3 will send the body using the standard 893s content-length form. Defaults to False. 893s 893s :param int body_pos: 893s Position to seek to in file-like body in the event of a retry or 893s redirect. Typically this won't need to be set because urllib3 will 893s auto-populate the value when needed. 893s """ 893s parsed_url = parse_url(url) 893s destination_scheme = parsed_url.scheme 893s 893s if headers is None: 893s headers = self.headers 893s 893s if not isinstance(retries, Retry): 893s retries = Retry.from_int(retries, redirect=redirect, default=self.retries) 893s 893s if release_conn is None: 893s release_conn = preload_content 893s 893s # Check host 893s if assert_same_host and not self.is_same_host(url): 893s raise HostChangedError(self, url, retries) 893s 893s # Ensure that the URL we're connecting to is properly encoded 893s if url.startswith("/"): 893s url = to_str(_encode_target(url)) 893s else: 893s url = to_str(parsed_url.url) 893s 893s conn = None 893s 893s # Track whether `conn` needs to be released before 893s # returning/raising/recursing. Update this variable if necessary, and 893s # leave `release_conn` constant throughout the function. That way, if 893s # the function recurses, the original value of `release_conn` will be 893s # passed down into the recursive call, and its value will be respected. 893s # 893s # See issue #651 [1] for details. 893s # 893s # [1] 893s release_this_conn = release_conn 893s 893s http_tunnel_required = connection_requires_http_tunnel( 893s self.proxy, self.proxy_config, destination_scheme 893s ) 893s 893s # Merge the proxy headers. Only done when not using HTTP CONNECT. We 893s # have to copy the headers dict so we can safely change it without those 893s # changes being reflected in anyone else's copy. 893s if not http_tunnel_required: 893s headers = headers.copy() # type: ignore[attr-defined] 893s headers.update(self.proxy_headers) # type: ignore[union-attr] 893s 893s # Must keep the exception bound to a separate variable or else Python 3 893s # complains about UnboundLocalError. 893s err = None 893s 893s # Keep track of whether we cleanly exited the except block. This 893s # ensures we do proper cleanup in finally. 893s clean_exit = False 893s 893s # Rewind body position, if needed. Record current position 893s # for future rewinds in the event of a redirect/retry. 893s body_pos = set_file_position(body, body_pos) 893s 893s try: 893s # Request a connection from the queue. 893s timeout_obj = self._get_timeout(timeout) 893s conn = self._get_conn(timeout=pool_timeout) 893s 893s conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment] 893s 893s # Is this a closed/new connection that requires CONNECT tunnelling? 893s if self.proxy is not None and http_tunnel_required and conn.is_closed: 893s try: 893s self._prepare_proxy(conn) 893s except (BaseSSLError, OSError, SocketTimeout) as e: 893s self._raise_timeout( 893s err=e, url=self.proxy.url, timeout_value=conn.timeout 893s ) 893s raise 893s 893s # If we're going to release the connection in ``finally:``, then 893s # the response doesn't need to know about the connection. Otherwise 893s # it will also try to release it and we'll have a double-release 893s # mess. 893s response_conn = conn if not release_conn else None 893s 893s # Make the request on the HTTPConnection object 893s > response = self._make_request( 893s conn, 893s method, 893s url, 893s timeout=timeout_obj, 893s body=body, 893s headers=headers, 893s chunked=chunked, 893s retries=retries, 893s response_conn=response_conn, 893s preload_content=preload_content, 893s decode_content=decode_content, 893s **response_kw, 893s ) 893s 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:791: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:492: in _make_request 893s raise new_e 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:468: in _make_request 893s self._validate_conn(conn) 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:1097: in _validate_conn 893s conn.connect() 893s /usr/lib/python3/dist-packages/urllib3/connection.py:611: in connect 893s self.sock = sock = self._new_conn() 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s 893s def _new_conn(self) -> socket.socket: 893s """Establish a socket connection and set nodelay settings on it. 893s 893s :return: New socket connection. 893s """ 893s try: 893s sock = connection.create_connection( 893s (self._dns_host, self.port), 893s self.timeout, 893s source_address=self.source_address, 893s socket_options=self.socket_options, 893s ) 893s except socket.gaierror as e: 893s raise NameResolutionError(self.host, self, e) from e 893s except SocketTimeout as e: 893s raise ConnectTimeoutError( 893s self, 893s f"Connection to {self.host} timed out. (connect timeout={self.timeout})", 893s ) from e 893s 893s except OSError as e: 893s > raise NewConnectionError( 893s self, f"Failed to establish a new connection: {e}" 893s ) from e 893s E urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 111] Connection refused 893s 893s /usr/lib/python3/dist-packages/urllib3/connection.py:218: NewConnectionError 893s 893s The above exception was the direct cause of the following exception: 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s > resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:667: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/urllib3/connectionpool.py:845: in urlopen 893s retries = retries.increment( 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = Retry(total=0, connect=None, read=False, redirect=None, status=None) 893s method = 'GET', url = '/gpt-2/encodings/main/vocab.bpe', response = None 893s error = NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused') 893s _pool = 893s _stacktrace = 893s 893s def increment( 893s self, 893s method: str | None = None, 893s url: str | None = None, 893s response: BaseHTTPResponse | None = None, 893s error: Exception | None = None, 893s _pool: ConnectionPool | None = None, 893s _stacktrace: TracebackType | None = None, 893s ) -> Retry: 893s """Return a new Retry object with incremented retry counters. 893s 893s :param response: A response object, or None, if the server did not 893s return a response. 893s :type response: :class:`~urllib3.response.BaseHTTPResponse` 893s :param Exception error: An error encountered during the request, or 893s None if the response was received successfully. 893s 893s :return: A new ``Retry`` object. 893s """ 893s if self.total is False and error: 893s # Disabled, indicate to re-raise the error. 893s raise reraise(type(error), error, _stacktrace) 893s 893s total = self.total 893s if total is not None: 893s total -= 1 893s 893s connect = self.connect 893s read = self.read 893s redirect = self.redirect 893s status_count = self.status 893s other = self.other 893s cause = "unknown" 893s status = None 893s redirect_location = None 893s 893s if error and self._is_connection_error(error): 893s # Connect retry? 893s if connect is False: 893s raise reraise(type(error), error, _stacktrace) 893s elif connect is not None: 893s connect -= 1 893s 893s elif error and self._is_read_error(error): 893s # Read retry? 893s if read is False or method is None or not self._is_method_retryable(method): 893s raise reraise(type(error), error, _stacktrace) 893s elif read is not None: 893s read -= 1 893s 893s elif error: 893s # Other retry? 893s if other is not None: 893s other -= 1 893s 893s elif response and response.get_redirect_location(): 893s # Redirect retry? 893s if redirect is not None: 893s redirect -= 1 893s cause = "too many redirects" 893s response_redirect_location = response.get_redirect_location() 893s if response_redirect_location: 893s redirect_location = response_redirect_location 893s status = response.status 893s 893s else: 893s # Incrementing because of a server error like a 500 in 893s # status_forcelist and the given method is in the allowed_methods 893s cause = ResponseError.GENERIC_ERROR 893s if response and response.status: 893s if status_count is not None: 893s status_count -= 1 893s cause = ResponseError.SPECIFIC_ERROR.format(status_code=response.status) 893s status = response.status 893s 893s history = self.history + ( 893s RequestHistory(method, url, error, status, redirect_location), 893s ) 893s 893s new_retry = self.new( 893s total=total, 893s connect=connect, 893s read=read, 893s redirect=redirect, 893s status=status_count, 893s other=other, 893s history=history, 893s ) 893s 893s if new_retry.is_exhausted(): 893s reason = error or ResponseError(cause) 893s > raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] 893s 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')) 893s 893s /usr/lib/python3/dist-packages/urllib3/util/retry.py:517: MaxRetryError 893s 893s During handling of the above exception, another exception occurred: 893s 893s def test_encoding_for_model(): 893s > enc = tiktoken.encoding_for_model("gpt2") 893s 893s tests/test_simple_public.py:26: 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s /usr/lib/python3/dist-packages/tiktoken/model.py:105: in encoding_for_model 893s return get_encoding(encoding_name_for_model(model_name)) 893s /usr/lib/python3/dist-packages/tiktoken/registry.py:86: in get_encoding 893s enc = Encoding(**constructor()) 893s /usr/lib/python3/dist-packages/tiktoken_ext/openai_public.py:18: in gpt2 893s mergeable_ranks = data_gym_to_mergeable_bpe_ranks( 893s /usr/lib/python3/dist-packages/tiktoken/load.py:103: in data_gym_to_mergeable_bpe_ranks 893s vocab_bpe_contents = read_file_cached(vocab_bpe_file, vocab_bpe_hash).decode() 893s /usr/lib/python3/dist-packages/tiktoken/load.py:63: in read_file_cached 893s contents = read_file(blobpath) 893s /usr/lib/python3/dist-packages/tiktoken/load.py:24: in read_file 893s resp = requests.get(blobpath) 893s /usr/lib/python3/dist-packages/requests/api.py:73: in get 893s return request("get", url, params=params, **kwargs) 893s /usr/lib/python3/dist-packages/requests/api.py:59: in request 893s return session.request(method=method, url=url, **kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:589: in request 893s resp = self.send(prep, **send_kwargs) 893s /usr/lib/python3/dist-packages/requests/sessions.py:703: in send 893s r = adapter.send(request, **kwargs) 893s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 893s 893s self = 893s request = , stream = False 893s timeout = Timeout(connect=None, read=None, total=None), verify = True 893s cert = None, proxies = OrderedDict() 893s 893s def send( 893s self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None 893s ): 893s """Sends PreparedRequest object. Returns Response object. 893s 893s :param request: The :class:`PreparedRequest ` being sent. 893s :param stream: (optional) Whether to stream the request content. 893s :param timeout: (optional) How long to wait for the server to send 893s data before giving up, as a float, or a :ref:`(connect timeout, 893s read timeout) ` tuple. 893s :type timeout: float or tuple or urllib3 Timeout object 893s :param verify: (optional) Either a boolean, in which case it controls whether 893s we verify the server's TLS certificate, or a string, in which case it 893s must be a path to a CA bundle to use 893s :param cert: (optional) Any user-provided SSL certificate to be trusted. 893s :param proxies: (optional) The proxies dictionary to apply to the request. 893s :rtype: requests.Response 893s """ 893s 893s try: 893s conn = self.get_connection_with_tls_context( 893s request, verify, proxies=proxies, cert=cert 893s ) 893s except LocationValueError as e: 893s raise InvalidURL(e, request=request) 893s 893s self.cert_verify(conn, request.url, verify, cert) 893s url = self.request_url(request, proxies) 893s self.add_headers( 893s request, 893s stream=stream, 893s timeout=timeout, 893s verify=verify, 893s cert=cert, 893s proxies=proxies, 893s ) 893s 893s chunked = not (request.body is None or "Content-Length" in request.headers) 893s 893s if isinstance(timeout, tuple): 893s try: 893s connect, read = timeout 893s timeout = TimeoutSauce(connect=connect, read=read) 893s except ValueError: 893s raise ValueError( 893s f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, " 893s f"or a single float to set both timeouts to the same value." 893s ) 893s elif isinstance(timeout, TimeoutSauce): 893s pass 893s else: 893s timeout = TimeoutSauce(connect=timeout, read=timeout) 893s 893s try: 893s resp = conn.urlopen( 893s method=request.method, 893s url=url, 893s body=request.body, 893s headers=request.headers, 893s redirect=False, 893s assert_same_host=False, 893s preload_content=False, 893s decode_content=False, 893s retries=self.max_retries, 893s timeout=timeout, 893s chunked=chunked, 893s ) 893s 893s except (ProtocolError, OSError) as err: 893s raise ConnectionError(err, request=request) 893s 893s except MaxRetryError as e: 893s if isinstance(e.reason, ConnectTimeoutError): 893s # TODO: Remove this in 3.0.0: see #2811 893s if not isinstance(e.reason, NewConnectionError): 893s raise ConnectTimeout(e, request=request) 893s 893s if isinstance(e.reason, ResponseError): 893s raise RetryError(e, request=request) 893s 893s if isinstance(e.reason, _ProxyError): 893s raise ProxyError(e, request=request) 893s 893s if isinstance(e.reason, _SSLError): 893s # This branch is for urllib3 v1.22 and later. 893s raise SSLError(e, request=request) 893s 893s > raise ConnectionError(e, request=request) 893s 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')) 893s 893s /usr/lib/python3/dist-packages/requests/adapters.py:700: ConnectionError 893s =========================== short test summary info ============================ 893s FAILED tests/test_encoding.py::test_simple - requests.exceptions.ConnectionEr... 893s FAILED tests/test_encoding.py::test_simple_repeated - requests.exceptions.Con... 893s FAILED tests/test_encoding.py::test_simple_regex - requests.exceptions.Connec... 893s FAILED tests/test_encoding.py::test_basic_encode - requests.exceptions.Connec... 893s FAILED tests/test_encoding.py::test_encode_empty - requests.exceptions.Connec... 893s FAILED tests/test_encoding.py::test_encode_bytes - requests.exceptions.Connec... 893s FAILED tests/test_encoding.py::test_encode_surrogate_pairs - requests.excepti... 893s FAILED tests/test_encoding.py::test_catastrophically_repetitive[r50k_base] - ... 893s FAILED tests/test_encoding.py::test_catastrophically_repetitive[cl100k_base] 893s FAILED tests/test_encoding.py::test_basic_roundtrip[r50k_base] - requests.exc... 893s FAILED tests/test_encoding.py::test_basic_roundtrip[cl100k_base] - requests.e... 893s FAILED tests/test_encoding.py::test_hyp_roundtrip[r50k_base] - requests.excep... 893s FAILED tests/test_encoding.py::test_hyp_roundtrip[cl100k_base] - requests.exc... 893s FAILED tests/test_encoding.py::test_single_token_roundtrip[r50k_base] - reque... 893s FAILED tests/test_encoding.py::test_single_token_roundtrip[cl100k_base] - req... 893s FAILED tests/test_encoding.py::test_special_token - requests.exceptions.Conne... 893s FAILED tests/test_encoding.py::test_hyp_special_ordinary[r50k_base] - request... 893s FAILED tests/test_encoding.py::test_hyp_special_ordinary[cl100k_base] - reque... 893s FAILED tests/test_encoding.py::test_batch_encode[r50k_base] - requests.except... 893s FAILED tests/test_encoding.py::test_batch_encode[cl100k_base] - requests.exce... 893s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[r50k_base] - requests... 893s FAILED tests/test_encoding.py::test_hyp_batch_roundtrip[cl100k_base] - reques... 893s FAILED tests/test_misc.py::test_encoding_for_model - requests.exceptions.Conn... 893s FAILED tests/test_offsets.py::test_hyp_offsets[cl100k_base] - requests.except... 893s FAILED tests/test_offsets.py::test_basic_offsets - requests.exceptions.Connec... 893s FAILED tests/test_pickle.py::test_pickle - requests.exceptions.ConnectionErro... 893s FAILED tests/test_simple_public.py::test_simple - requests.exceptions.Connect... 893s FAILED tests/test_simple_public.py::test_encoding_for_model - requests.except... 893s ======================== 28 failed, 2 passed in 34.32s ========================= 894s autopkgtest [09:49:51]: test pybuild-autopkgtest: -----------------------] 895s pybuild-autopkgtest FAIL non-zero exit status 25 895s autopkgtest [09:49:52]: test pybuild-autopkgtest: - - - - - - - - - - results - - - - - - - - - - 895s autopkgtest [09:49:52]: @@@@@@@@@@@@@@@@@@@@ summary 895s pybuild-autopkgtest FAIL non-zero exit status 25 909s nova [W] Using flock in prodstack6-arm64 909s Creating nova instance adt-plucky-arm64-tiktoken-20241203-093457-juju-7f2275-prod-proposed-migration-environment-2-d114b136-f376-4b9b-991c-5b6e8cc4b8f1 from image adt/ubuntu-plucky-arm64-server-20241203.img (UUID b9293590-1195-42ea-ba16-5ab4b1e94eab)...