Skip to content

Commit e79924d

Browse files
committed
Fix downloading GeoIP database
fixes ZeroNetX#222
1 parent 714729e commit e79924d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

plugins/Sidebar/SidebarPlugin.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def actionSidebarGetHtmlTag(self, to):
602602
def downloadGeoLiteDb(self, db_path):
603603
import gzip
604604
import shutil
605-
from util import helper
605+
import requests
606606

607607
if config.offline or config.tor == 'always':
608608
return False
@@ -617,19 +617,18 @@ def downloadGeoLiteDb(self, db_path):
617617
downloadl_err = None
618618
try:
619619
# Download
620-
response = helper.httpRequest(db_url)
621-
data_size = response.getheader('content-length')
620+
response = requests.get(db_url, stream=True)
621+
data_size = response.headers.get('content-length')
622+
if data_size is None:
623+
data.write(response.content)
624+
data_size = int(data_size)
622625
data_recv = 0
623626
data = io.BytesIO()
624-
while True:
625-
buff = response.read(1024 * 512)
626-
if not buff:
627-
break
627+
for buff in response.iter_content(chunk_size=1024 * 512):
628628
data.write(buff)
629629
data_recv += 1024 * 512
630-
if data_size:
631-
progress = int(float(data_recv) / int(data_size) * 100)
632-
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
630+
progress = int(float(data_recv) / data_size * 100)
631+
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
633632
self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell())
634633
data.seek(0)
635634

0 commit comments

Comments
 (0)