Repository: planetlabs/planet-client-python
Issue: Asset download fails for Landsat imagery

As demonstrated in the following notebook: https://github.com/planetlabs/notebooks/blob/master/jupyter-notebooks/landsat-ps-comparison/landsat-ps-comparison.ipynb

Landsat download fails using V2 of our Client, even though Planet imagery download is successful. 


Changed files:
tests/unit/test_models.py, planet/models.py

diff --git a/planet/models.py b/planet/models.py
index ab38d8e..e2e7761 100644
--- a/planet/models.py
+++ b/planet/models.py
@@ -19,7 +19,8 @@ from pathlib import Path
 import random
 import re
 import string
-from typing import AsyncGenerator, Callable, List
+from typing import AsyncGenerator, Callable, List, Optional
+from urllib.parse import urlparse
 
 import httpx
 from tqdm.asyncio import tqdm
@@ -174,13 +175,12 @@ def _get_filename_from_headers(headers):
     return match.group(1) if match else None
 
 
-def _get_filename_from_url(url):
-    """Get a filename from a URL.
+def _get_filename_from_url(url: str) -> Optional[str]:
+    """Get a filename from a url.
 
-    :returns: a filename (i.e. ``basename``)
-    :rtype: str or None
+    Getting a name for Landsat imagery uses this function.
     """
-    path = url.path
+    path = urlparse(url).path
     name = path[path.rfind('/') + 1:]
     return name or None
 
diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py
index 434c339..99cb11f 100644
--- a/tests/unit/test_models.py
+++ b/tests/unit/test_models.py
@@ -19,7 +19,6 @@ import os
 from pathlib import Path
 import re
 
-from httpx import URL
 import pytest
 
 from planet import models
@@ -30,7 +29,7 @@ LOGGER = logging.getLogger(__name__)
 
 def test_StreamingBody_name_filename():
     r = MagicMock(name='response')
-    r.url = URL('https://planet.com/path/to/example.tif?foo=f6f1')
+    r.url = 'https://planet.com/path/to/example.tif?foo=f6f1'
     r.headers = {
         'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
         'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -45,7 +44,7 @@ def test_StreamingBody_name_filename():
 
 def test_StreamingBody_name_url():
     r = MagicMock(name='response')
-    r.url = URL('https://planet.com/path/to/example.tif?foo=f6f1')
+    r.url = 'https://planet.com/path/to/example.tif?foo=f6f1'
     r.headers = {
         'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
         'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -60,7 +59,7 @@ def test_StreamingBody_name_url():
 
 def test_StreamingBody_name_content():
     r = MagicMock(name='response')
-    r.url = URL('https://planet.com/path/to/noname/')
+    r.url = 'https://planet.com/path/to/noname/'
     r.headers = {
         'date': 'Thu, 14 Feb 2019 16:13:26 GMT',
         'last-modified': 'Wed, 22 Nov 2017 17:22:31 GMT',
@@ -102,12 +101,12 @@ def test__get_filename_from_headers(headers, expected):
 @pytest.mark.parametrize(
     'url,expected',
     [
-        (URL('https://planet.com/'), None),
-        (URL('https://planet.com/path/to/'), None),
-        (URL('https://planet.com/path/to/example.tif'), 'example.tif'),
-        (URL('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz'),
+        ('https://planet.com/', None),
+        ('https://planet.com/path/to/', None),
+        ('https://planet.com/path/to/example.tif', 'example.tif'),
+        ('https://planet.com/path/to/example.tif?foo=f6f1&bar=baz',
          'example.tif'),
-        (URL('https://planet.com/path/to/example.tif?foo=f6f1#quux'),
+        ('https://planet.com/path/to/example.tif?foo=f6f1#quux',
          'example.tif'),
     ])
 def test__get_filename_from_url(url, expected):