requests -> urllib3

pull/30771/head
royjr 1 year ago
parent f50ecf973d
commit 7ca39e6189
  1. 22
      system/qcomgpsd/qcomgpsd.py

@ -5,8 +5,8 @@ import signal
import itertools import itertools
import math import math
import time import time
import requests import urllib3
from requests.exceptions import RequestException from urllib3.exceptions import HTTPError
import shutil import shutil
import subprocess import subprocess
import datetime import datetime
@ -102,23 +102,23 @@ def gps_enabled() -> bool:
raise Exception("failed to execute QGPS mmcli command") from exc raise Exception("failed to execute QGPS mmcli command") from exc
def download_assistance(): def download_assistance():
http = urllib3.PoolManager()
try: try:
response = requests.head(ASSISTANCE_URL, timeout=2) response = http.request('HEAD', ASSISTANCE_URL)
bytes_n = int(response.headers.get('content-length', 0)) content_length = int(response.headers.get('content-length', 0))
if bytes_n > 1e5: if content_length > 1e5:
cloudlog.error("Qcom assistance data larger than expected") cloudlog.error("Qcom assistance data larger than expected")
return return
response = requests.get(ASSISTANCE_URL, timeout=5, stream=True) with http.request('GET', ASSISTANCE_URL, preload_content=False) as resp, open(ASSIST_DATA_FILE_DOWNLOAD, 'wb') as out_file:
with open(ASSIST_DATA_FILE_DOWNLOAD, 'wb') as fp: shutil.copyfileobj(resp, out_file)
for chunk in response.iter_content(chunk_size=8192):
fp.write(chunk)
os.rename(ASSIST_DATA_FILE_DOWNLOAD, ASSIST_DATA_FILE) os.rename(ASSIST_DATA_FILE_DOWNLOAD, ASSIST_DATA_FILE)
except RequestException: except HTTPError as e:
cloudlog.exception("Failed to download assistance file") cloudlog.exception("Failed to download assistance file: {}".format(e))
return return
def downloader_loop(event): def downloader_loop(event):

Loading…
Cancel
Save