Skip to content

Commit

Permalink
fix aiohttp InvalidURL exception when fetching media player image (ho…
Browse files Browse the repository at this point in the history
…me-assistant#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
  • Loading branch information
azogue authored and michaeldavie committed Jul 31, 2018
1 parent 0aeb93f commit 5435462
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion homeassistant/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"""
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
Expand Down Expand Up @@ -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)}

Expand Down

0 comments on commit 5435462

Please sign in to comment.