Skip to content

fix: Fixed requests.get() function call by adding timeout parameter #7742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/instruct_pix2pix/train_instruct_pix2pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def convert_to_np(image, resolution):


def download_image(url):
image = PIL.Image.open(requests.get(url, stream=True).raw)
image = PIL.Image.open(requests.get(url, stream=True, timeout=10).raw)
image = PIL.ImageOps.exif_transpose(image)
image = image.convert("RGB")
return image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def convert_to_np(image, resolution):


def download_image(url):
image = PIL.Image.open(requests.get(url, stream=True).raw)
image = PIL.Image.open(requests.get(url, stream=True, timeout=10).raw)
image = PIL.ImageOps.exif_transpose(image)
image = image.convert("RGB")
return image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ def download_from_original_stable_diffusion_ckpt(
config_url = "https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/x4-upscaling.yaml"

if config_url is not None:
original_config_file = BytesIO(requests.get(config_url).content)
original_config_file = BytesIO(requests.get(config_url, timeout=10).content)
else:
with open(original_config_file, "r") as f:
original_config_file = f.read()
Expand Down
2 changes: 1 addition & 1 deletion scripts/convert_dance_diffusion_to_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, global_args):

def download(model_name):
url = MODELS_MAP[model_name]["url"]
r = requests.get(url, stream=True)
r = requests.get(url, stream=True, timeout=10)

local_filename = f"./{model_name}.ckpt"
with open(local_filename, "wb") as fp:
Expand Down
2 changes: 1 addition & 1 deletion scripts/convert_vae_pt_to_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def vae_pt_to_vae_diffuser(
):
# Only support V1
r = requests.get(
" https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml"
" https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml", timeout=10
)
io_obj = io.BytesIO(r.content)

Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/loaders/single_file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def infer_original_config_file(class_name, checkpoint):
else:
config_url = CONFIG_URLS["v1"]

original_config_file = BytesIO(requests.get(config_url).content)
original_config_file = BytesIO(requests.get(config_url, timeout=10).content)

return original_config_file

Expand All @@ -402,7 +402,7 @@ def is_valid_url(url):
original_config_file = fp.read()

elif is_valid_url(original_config_file):
original_config_file = BytesIO(requests.get(original_config_file).content)
original_config_file = BytesIO(requests.get(original_config_file, timeout=10).content)

else:
raise ValueError("Invalid `original_config_file` provided. Please set it to a valid file path or URL.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ def download_from_original_stable_diffusion_ckpt(
config_url = "https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/x4-upscaling.yaml"

if config_url is not None:
original_config_file = BytesIO(requests.get(config_url).content)
original_config_file = BytesIO(requests.get(config_url, timeout=10).content)
else:
with open(original_config_file, "r") as f:
original_config_file = f.read()
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/utils/loading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def load_image(
"""
if isinstance(image, str):
if image.startswith("http://") or image.startswith("https://"):
image = PIL.Image.open(requests.get(image, stream=True).raw)
image = PIL.Image.open(requests.get(image, stream=True, timeout=10).raw)
elif os.path.isfile(image):
image = PIL.Image.open(image)
else:
Expand Down
6 changes: 3 additions & 3 deletions src/diffusers/utils/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -
# local_path can be passed to correct images of tests
return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
elif arry.startswith("http://") or arry.startswith("https://"):
response = requests.get(arry)
response = requests.get(arry, timeout=10)
response.raise_for_status()
arry = np.load(BytesIO(response.content))
elif os.path.isfile(arry):
Expand All @@ -417,7 +417,7 @@ def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -


def load_pt(url: str):
response = requests.get(url)
response = requests.get(url, timeout=10)
response.raise_for_status()
arry = torch.load(BytesIO(response.content))
return arry
Expand All @@ -436,7 +436,7 @@ def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
"""
if isinstance(image, str):
if image.startswith("http://") or image.startswith("https://"):
image = PIL.Image.open(requests.get(image, stream=True).raw)
image = PIL.Image.open(requests.get(image, stream=True, timeout=10).raw)
elif os.path.isfile(image):
image = PIL.Image.open(image)
else:
Expand Down
2 changes: 1 addition & 1 deletion utils/fetch_latest_release_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch_all_branches(user, repo):
page = 1 # Start from first page
while True:
# Make a request to the GitHub API for the branches
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/branches", params={"page": page})
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/branches", params={"page": page}, timeout=10)

# Check if the request was successful
if response.status_code == 200:
Expand Down
4 changes: 2 additions & 2 deletions utils/notify_slack_about_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def check_pypi_for_latest_release(library_name):
"""Check PyPI for the latest release of the library."""
response = requests.get(f"https://pypi.org/pypi/{library_name}/json")
response = requests.get(f"https://pypi.org/pypi/{library_name}/json", timeout=10)
if response.status_code == 200:
data = response.json()
return data["info"]["version"]
Expand All @@ -38,7 +38,7 @@ def check_pypi_for_latest_release(library_name):
def get_github_release_info(github_repo):
"""Fetch the latest release info from GitHub."""
url = f"https://api.github.com/repos/{github_repo}/releases/latest"
response = requests.get(url)
response = requests.get(url, timeout=10)

if response.status_code == 200:
data = response.json()
Expand Down