diff --git a/examples/uploader/_localrepo.py b/examples/uploader/_localrepo.py index edae65821b..c4d746a34d 100644 --- a/examples/uploader/_localrepo.py +++ b/examples/uploader/_localrepo.py @@ -12,8 +12,8 @@ import os from datetime import datetime, timedelta, timezone -import requests from securesystemslib.signer import CryptoSigner, Signer +from urllib3 import request from tuf.api.exceptions import RepositoryError from tuf.api.metadata import Metadata, MetaFile, TargetFile, Targets @@ -92,8 +92,9 @@ def close(self, role_name: str, md: Metadata) -> None: # Upload using "api/role" uri = f"{self.base_url}/api/role/{role_name}" - r = requests.post(uri, data=md.to_bytes(JSONSerializer()), timeout=5) - r.raise_for_status() + r = request("POST", uri, body=md.to_bytes(JSONSerializer()), timeout=5) + if r.status != 200: + raise RuntimeError(f"HTTP error {r.status}") def add_target(self, role: str, targetpath: str) -> bool: """Add target to roles metadata and submit new metadata version""" @@ -124,8 +125,8 @@ def add_delegation(self, role: str) -> bool: data = {signer.public_key.keyid: signer.public_key.to_dict()} url = f"{self.base_url}/api/delegation/{role}" - r = requests.post(url, data=json.dumps(data), timeout=5) - if r.status_code != 200: + r = request("POST", url, body=json.dumps(data), timeout=5) + if r.status != 200: print(f"delegation failed with {r}") return False diff --git a/verify_release b/verify_release index 549b7bab84..f6ae8330f0 100755 --- a/verify_release +++ b/verify_release @@ -10,7 +10,6 @@ on GitHub and PyPI match the built release artifacts. """ import argparse -import json import os import subprocess import sys @@ -20,10 +19,10 @@ from typing import Optional try: import build as _ # type: ignore[import-not-found] # noqa: F401 - import requests + from urllib3 import request except ImportError: - print("Error: verify_release requires modules 'requests' and 'build':") - print(" pip install requests build") + print("Error: verify_release requires modules 'urllib3' and 'build':") + print(" pip install urllib3 build") sys.exit(1) # Project variables @@ -75,9 +74,7 @@ def get_git_version() -> str: def get_github_version() -> str: """Return version string of latest GitHub release""" release_json = f"https://api.github.com/repos/{GITHUB_ORG}/{GITHUB_PROJECT}/releases/latest" - releases = json.loads( - requests.get(release_json, timeout=HTTP_TIMEOUT).content - ) + releases = request("GET", release_json, timeout=HTTP_TIMEOUT).json() return releases["tag_name"][1:] @@ -106,9 +103,11 @@ def verify_github_release(version: str, compare_dir: str) -> bool: with TemporaryDirectory() as github_dir: for filename in [tar, wheel]: url = f"{base_url}/v{version}/{filename}" - response = requests.get(url, stream=True, timeout=HTTP_TIMEOUT) + response = request( + "GET", url, preload_content=False, timeout=HTTP_TIMEOUT + ) with open(os.path.join(github_dir, filename), "wb") as f: - for data in response.iter_content(): + for data in response.stream(): f.write(data) return cmp(