Skip to content

Conversation

@jthetzel
Copy link
Contributor

@jthetzel jthetzel commented Nov 23, 2025

This pull request allows contextily users to pass an optional headers parameter that will be included in the _retryer function's request.get call to the tile server.

We use titiler with cloud optimized geotiffs for tiles and often authenticate the titiler server with an authentication bearer token in the http request headers. This change allows us to use contextily with our authenticated titiler.

Opening this pull request for discussion in case it is of use to others. Please let me know if there is a simpler way to use contextily with custom headers.

Related issue: #267

> contextily/tests/test_cx.py:806: RuntimeWarning: More than 20
 figures have been opened. Figures created through the pyplot
 interface (`matplotlib.pyplot.figure`) are retained until explicitly
 closed and may consume too much memory. (To control this warning,
 see the rcParam `figure.max_open_warning`). Consider using
 `matplotlib.pyplot.close()`.
@jthetzel
Copy link
Contributor Author

jthetzel commented Nov 23, 2025

This also updates two unrelated pytest expected sums which were failing ( 4cfa350 ).

I can reproduce the pytest failure in the main branch head ( 851b77b ) to confirm it is unrelated to this pull request, to the best of my understanding.

@jthetzel
Copy link
Contributor Author

This also removes an unrelated matplotlib pytest warning ( ad65bcb ).

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this approach is fine. Just one comment - can we catch a situation when a user passes custom user-agent in headers?

@jthetzel
Copy link
Contributor Author

jthetzel commented Nov 24, 2025

Thanks, @martinfleis . Which behavior do you prefer?

  1. Silently override custom user-agent with contextily user-agent (currently in this PR),
  2. Print warning and override custom user-agent with contextily user-agent,
  3. Silently use custom user-agent, ignoring contextily user-agent,
  4. Print warning and use custom user-agent, ignoring contextily user-agent, or
  5. Raise exception.

My very mild preference is for option 3 to pass responsibility to the user, but I defer to you. I implemented option 1, because I was unsusre of the significance of the contextily USER_AGENT.

@martinfleis
Copy link
Member

I would go with the option 3. We generate it to essentially get a unique identifier of the process that is fetching the tiles. I am happy to let users override this without a warning.

@jthetzel
Copy link
Contributor Author

jthetzel commented Nov 24, 2025

After review, option 3 was already implemented. Added a test to confirm the user provided user-agent overrides the contextily user-agent ( 546fdc8 ).

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@martinfleis martinfleis merged commit cb025b6 into geopandas:main Nov 24, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants