timezoned: set headers (#29725)

* timezoned: set headers

* Update system/timezoned.py

* this is useful

* newline
pull/29742/head
Shane Smiskol 2 years ago committed by GitHub
parent 18fbc1c29a
commit 2dd7a6fc64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      system/timezoned.py

@ -11,6 +11,9 @@ from timezonefinder import TimezoneFinder
from openpilot.common.params import Params from openpilot.common.params import Params
from openpilot.system.hardware import AGNOS from openpilot.system.hardware import AGNOS
from openpilot.system.swaglog import cloudlog from openpilot.system.swaglog import cloudlog
from openpilot.system.version import get_version
REQUEST_HEADERS = {'User-Agent': "openpilot-" + get_version()}
def set_timezone(valid_timezones, timezone): def set_timezone(valid_timezones, timezone):
@ -18,7 +21,7 @@ def set_timezone(valid_timezones, timezone):
cloudlog.error(f"Timezone not supported {timezone}") cloudlog.error(f"Timezone not supported {timezone}")
return return
cloudlog.debug(f"Setting timezone to {timezone}") cloudlog.info(f"Setting timezone to {timezone}")
try: try:
if AGNOS: if AGNOS:
tzpath = os.path.join("/usr/share/zoneinfo/", timezone) tzpath = os.path.join("/usr/share/zoneinfo/", timezone)
@ -58,7 +61,7 @@ def main() -> NoReturn:
if location is None: if location is None:
cloudlog.debug("Setting timezone based on IP lookup") cloudlog.debug("Setting timezone based on IP lookup")
try: try:
r = requests.get("https://ipapi.co/timezone", timeout=10) r = requests.get("https://ipapi.co/timezone", headers=REQUEST_HEADERS, timeout=10)
if r.status_code == 200: if r.status_code == 200:
set_timezone(valid_timezones, r.text) set_timezone(valid_timezones, r.text)
else: else:

Loading…
Cancel
Save