fix aiohttp InvalidURL exception when fetching media player image (#15572)
* fix aiohttp InvalidURL exception when fetching media player image The first call for the HA proxy (`/api/media_player_proxy/media_player.kodi?token=...&cache=...`) is receiving relative urls that are failing, this is a simple fix to precede the base_url when hostname is None. * fix import location and sort stdlib importspull/15603/head
parent
5cf9cd686c
commit
9a8389060c
|
@ -6,12 +6,13 @@ https://home-assistant.io/components/media_player/
|
|||
"""
|
||||
import asyncio
|
||||
import base64
|
||||
import collections
|
||||
from datetime import timedelta
|
||||
import functools as ft
|
||||
import collections
|
||||
import hashlib
|
||||
import logging
|
||||
from random import SystemRandom
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from aiohttp import web
|
||||
from aiohttp.hdrs import CONTENT_TYPE, CACHE_CONTROL
|
||||
|
@ -956,6 +957,9 @@ async def _async_fetch_image(hass, url):
|
|||
cache_images = ENTITY_IMAGE_CACHE[CACHE_IMAGES]
|
||||
cache_maxsize = ENTITY_IMAGE_CACHE[CACHE_MAXSIZE]
|
||||
|
||||
if urlparse(url).hostname is None:
|
||||
url = hass.config.api.base_url + url
|
||||
|
||||
if url not in cache_images:
|
||||
cache_images[url] = {CACHE_LOCK: asyncio.Lock(loop=hass.loop)}
|
||||
|
||||
|
|
Loading…
Reference in New Issue