Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

import_util: Use `get_file_from_url` to properly handle file request.

PieterCKa10f0afd67db
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index 43e4b67800f..17fc1b3d0ff 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -611,7 +611,7 @@ def get_avatar(avatar_dir: str, size_url_suffix: str, avatar_upload_item: list[s
# Adjust the avatar size for a typical Slack user.
avatar_url += size_url_suffix
- response = requests.get(avatar_url, stream=True)
+ response = request_file_stream(avatar_url)
with open(image_path, "wb") as image_file:
shutil.copyfileobj(response.raw, image_file)
shutil.copy(image_path, original_image_path)
@@ -730,7 +730,7 @@ def build_realm_emoji(realm_id: int, name: str, id: int, file_name: str) -> Zerv
def get_emojis(emoji_dir: str, emoji_url: str, emoji_path: str) -> str | None:
upload_emoji_path = os.path.join(emoji_dir, emoji_path)
- response = requests.get(emoji_url, stream=True)
+ response = request_file_stream(emoji_url)
os.makedirs(os.path.dirname(upload_emoji_path), exist_ok=True)
with open(upload_emoji_path, "wb") as emoji_file:
shutil.copyfileobj(response.raw, emoji_file)
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index 1f837047cf9..f80a46faa31 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -45,6 +45,7 @@ from zerver.data_import.import_util import (
make_subscriber_map,
process_avatars,
process_emojis,
+ request_file_stream,
validate_user_emails_for_import,
)
from zerver.data_import.sequencer import NEXT_ID
@@ -1614,7 +1615,7 @@ def fetch_team_icons(
if icon_url is None:
return []
- response = requests.get(icon_url, stream=True)
+ response = request_file_stream(icon_url)
response_raw = response.raw
realm_id = zerver_realm["id"]