Skip to content

Commit ed582e2

Browse files
Use HTTP urls and improve exception handling (#39)
* Re-raise exceptions * Try using http urls I think some of the issues are coming from https validation failing
1 parent cdcda1b commit ed582e2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

minecraft_model_reader/api/resource_pack/java/download_resources.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
INCLUDE_SNAPSHOT = False
1818

1919

20+
def get_http(url: str) -> str:
21+
"""Strip https from the url."""
22+
if url.startswith("https://"):
23+
return "http" + url[5:]
24+
return url
25+
26+
2027
def get_launcher_manifest() -> dict:
2128
global launcher_manifest
2229
if launcher_manifest is None:
2330
log.info("Downloading java launcher manifest file.")
2431
with urlopen(
25-
"https://launchermeta.mojang.com/mc/game/version_manifest.json", timeout=20
32+
get_http("https://launchermeta.mojang.com/mc/game/version_manifest.json"),
33+
timeout=20,
2634
) as manifest:
2735
launcher_manifest = json.load(manifest)
2836
log.info("Finished downloading java launcher manifest file.")
@@ -56,13 +64,13 @@ def get_latest_iter() -> Generator[float, None, JavaResourcePack]:
5664
new_version = get_launcher_manifest()["latest"]["snapshot"]
5765
else:
5866
new_version = get_launcher_manifest()["latest"]["release"]
59-
except Exception as e:
67+
except Exception:
6068
if os.path.isdir(vanilla_rp_path):
6169
log.error(
6270
"Could not download the launcher manifest. The resource pack seems to be present so using that."
6371
)
6472
else:
65-
raise e
73+
raise
6674
else:
6775
has_new_pack = False
6876
if os.path.isfile(os.path.join(vanilla_rp_path, "version")):
@@ -166,11 +174,11 @@ def download_resources_iter(
166174
raise Exception(f"Could not find Java resource pack for version {version}.")
167175

168176
try:
169-
with urlopen(version_url, timeout=20) as vm:
177+
with urlopen(get_http(version_url), timeout=20) as vm:
170178
version_manifest = json.load(vm)
171179
version_client_url = version_manifest["downloads"]["client"]["url"]
172180

173-
downloader = download_with_retry(version_client_url)
181+
downloader = download_with_retry(get_http(version_client_url))
174182
try:
175183
while True:
176184
yield next(downloader) / 2
@@ -203,10 +211,10 @@ def download_resources_iter(
203211
if "pack.png" in client.namelist():
204212
client.extract("pack.png", path)
205213

206-
except Exception as e:
214+
except Exception:
207215
log.error(
208216
f"Failed to download and extract the Java resource pack for version {version}.",
209217
exc_info=True,
210218
)
211-
raise e
219+
raise
212220
log.info(f"Finished downloading Java resource pack for version {version}")

0 commit comments

Comments
 (0)