Skip to content

Commit 4effd06

Browse files
authored
Merge pull request #97 from smellman/dev-fix-94
#94 use requests module instead of urllib.request to download preset
2 parents b1d01b1 + 0f193cb commit 4effd06

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

gtfs_go_dialog.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import os
55
import shutil
66
import tempfile
7-
import urllib
87
import uuid
8+
from typing import Optional
99

10+
import requests
1011
from qgis.core import (
1112
QgsCoordinateReferenceSystem,
1213
QgsProject,
@@ -142,8 +143,15 @@ def make_combobox_text(self, data):
142143
"""
143144
return "[" + data["country"] + "]" + "[" + data["region"] + "]" + data["name"]
144145

145-
def download_zip(self, url: str) -> str:
146-
data = urllib.request.urlopen(url).read()
146+
def download_zip(self, url: str) -> Optional[str]:
147+
response = requests.get(url)
148+
if response.status_code != 200:
149+
self.iface.messageBar().pushCritical(
150+
self.tr("Error"),
151+
self.tr("Failed to download GTFS data from the URL: ") + url,
152+
)
153+
return None
154+
data = response.content
147155
download_path = os.path.join(TEMP_DIR, str(uuid.uuid4()) + ".zip")
148156
with open(download_path, mode="wb") as f:
149157
f.write(data)
@@ -201,6 +209,8 @@ def execution(self):
201209
for feed_info in self.get_target_feed_infos():
202210
if feed_info["path"].startswith("http"):
203211
feed_info["path"] = self.download_zip(feed_info["path"])
212+
if feed_info["path"] is None:
213+
continue
204214

205215
output_dir = os.path.join(
206216
self.outputDirFileWidget.filePath(), feed_info["dir"]

0 commit comments

Comments
 (0)