Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

catch image=None in _retryer() #252

Open
@veenstrajelmer

Description

Follow-up from #247

There are still Nonetype related errors after fixing #248.

When array[0] is None, the code fails on line 682 with an AttributeError:

/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/plotting.py:134: in add_basemap
 image, extent = bounds2img(
/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/tile.py:287: in bounds2img
 merged, extent = _merge_tiles(tiles, arrays)
/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/tile.py:682: in _merge_tiles
 h, w, d = arrays[0].shape
E AttributeError: 'NoneType' object has no attribute 'shape'

If the first array is valid, but any of the other arrays is None, the issue surfaces a bit lower as a TypeError:

/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/plotting.py:134: in add_basemap
 image, extent = bounds2img(
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/tile.py:287: in bounds2img
 merged, extent = _merge_tiles(tiles, arrays)
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/tile.py:692: in _merge_tiles
 img[y * h : (y + 1) * h, x * w : (x + 1) * w, :] = arr
E TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

I cannot fully grasp what is happening here. I imagined that image=None, and was looking at this part of the code:

with io.BytesIO(request.content) as image_stream:
image = Image.open(image_stream).convert("RGBA")
array = np.asarray(image)
image.close()

So I guess that would lead to this minimal example:
import numpy as np
image = None
array = np.asarray(image)
print(array.shape)

However, this prints () and does not give the error above. @martinfleis do you have an idea how the image variable looks like when this error occurs? Or is my minimal reproduction example faulty?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /