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
pull/15603/head
Eugenio Panadero 2018-07-20 15:18:02 +02:00 committed by Paulus Schoutsen
parent 5cf9cd686c
commit 9a8389060c
1 changed files with 5 additions and 1 deletions

View File

@ -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)}