mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
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 imports
This commit is contained in:
parent
5cf9cd686c
commit
9a8389060c
@ -6,12 +6,13 @@ https://home-assistant.io/components/media_player/
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
|
import collections
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import collections
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
from random import SystemRandom
|
from random import SystemRandom
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiohttp.hdrs import CONTENT_TYPE, CACHE_CONTROL
|
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_images = ENTITY_IMAGE_CACHE[CACHE_IMAGES]
|
||||||
cache_maxsize = ENTITY_IMAGE_CACHE[CACHE_MAXSIZE]
|
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:
|
if url not in cache_images:
|
||||||
cache_images[url] = {CACHE_LOCK: asyncio.Lock(loop=hass.loop)}
|
cache_images[url] = {CACHE_LOCK: asyncio.Lock(loop=hass.loop)}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user