Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename settings module's default_accept_language, default_referer, and default_user_agent #1129

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

- add type annotations to all public and private functions throughout package (#1107)
- improve docstrings throughout package (#1116)
- improve logging and warnings throughout package (#1125)
- remove functionality previously deprecated in v1 (#1113 #1122)
- drop Python 3.8 support (#1106)
- increase add_node_elevations_google default batch_size to 512 to match Google's limit (#1115)
- make which_result function parameter consistently able to accept a list throughout package (#1113)
- make utils_geo.bbox_from_point function return a tuple of floats for consistency with rest of package (#1113)
- improve logging and warnings throughout package (#1125)
- fix bug in \_downloader.\_save_to_cache function usage (#1107)
- fix bug in handling requests ConnectionError when querying Overpass status endpoint (#1113)
- minor fixes throughout to address inconsistencies revealed by type enforcement (#1107 #1114)
- fix minor bugs throughout to address inconsistencies revealed by type enforcement (#1107 #1114)
- rename settings module's default_accept_language, default_referer, and default_user_agent (#1129)
- rename osm_xml module to \_osm_xml to make it private, as all its functions are private (#1113)
- rename private \_downloader module to \_http (#1114)
- remove unnecessary private \_api module (#1114)
Expand Down
21 changes: 10 additions & 11 deletions osmnx/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,32 @@ def _get_http_headers(
user_agent: str | None = None, referer: str | None = None, accept_language: str | None = None
) -> dict[str, str]:
"""
Update the default requests HTTP headers with OSMnx info.
Update the default requests HTTP headers with OSMnx information.

Parameters
----------
user_agent
The user agent string. If None, use the OSMnx default.
The user agent. If None, use `settings.http_user_agent` value.
referer
The referer string. If None, use the OSMnx default.
The referer. If None, use `settings.http_referer` value.
accept_language
The accept language. Make it explicit for consistent Nominatim result
sorting.
The accept language. If None, use `settings.http_accept_language`
value.

Returns
-------
headers
"""
if user_agent is None:
user_agent = settings.default_user_agent
user_agent = settings.http_user_agent
if referer is None:
referer = settings.default_referer
referer = settings.http_referer
if accept_language is None:
accept_language = settings.default_accept_language
accept_language = settings.http_accept_language

info = {"User-Agent": user_agent, "referer": referer, "Accept-Language": accept_language}
headers = dict(requests.utils.default_headers())
headers.update(
{"User-Agent": user_agent, "referer": referer, "Accept-Language": accept_language}
)
headers.update(info)
return headers


Expand Down
26 changes: 14 additions & 12 deletions osmnx/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
data_folder : str | Path
Path to folder in which to save/load graph files by default. Default is
`"./data"`.
default_accept_language : str
HTTP header accept-language. Default is `"en"`.
default_access : str
Default filter for OSM "access" key. Default is `'["access"!~"private"]'`.
Filter for the OSM "access" key. Default is `'["access"!~"private"]'`.
Note that also filtering out "access=no" ways prevents including
transit-only bridges (e.g., Tilikum Crossing) from appearing in drivable
road network (e.g., `'["access"!~"private|no"]'`). However, some drivable
Expand All @@ -38,12 +36,6 @@
default_crs : str
Default coordinate reference system to set when creating graphs. Default
is `"epsg:4326"`.
default_referer : str
HTTP header referer. Default is
`"OSMnx Python package (https://github.com/gboeing/osmnx)"`.
default_user_agent : str
HTTP header user-agent. Default is
`"OSMnx Python package (https://github.com/gboeing/osmnx)"`.
doh_url_template : str | None
Endpoint to resolve DNS-over-HTTPS if local DNS resolution fails. Set to
None to disable DoH, but see `downloader._config_dns` documentation for
Expand All @@ -54,6 +46,16 @@
`"https://maps.googleapis.com/maps/api/elevation/json?locations={locations}&key={key}"`
One example of an alternative equivalent would be Open Topo Data:
`"https://api.opentopodata.org/v1/aster30m?locations={locations}&key={key}"`
http_accept_language : str
HTTP header accept-language. Default is `"en"`. Note that Nominatim's
default language is "en" and it can sort result importance scores
differently if a different language is specified.
http_referer : str
HTTP header referer. Default is
`"OSMnx Python package (https://github.com/gboeing/osmnx)"`.
http_user_agent : str
HTTP header user-agent. Default is
`"OSMnx Python package (https://github.com/gboeing/osmnx)"`.
imgs_folder : str | Path
Path to folder in which to save plotted images by default. Default is
`"./images"`.
Expand Down Expand Up @@ -146,15 +148,15 @@
cache_folder: str | Path = "./cache"
cache_only_mode: bool = False
data_folder: str | Path = "./data"
default_accept_language: str = "en"
default_access: str = '["access"!~"private"]'
default_crs: str = "epsg:4326"
default_referer: str = "OSMnx Python package (https://github.com/gboeing/osmnx)"
default_user_agent: str = "OSMnx Python package (https://github.com/gboeing/osmnx)"
doh_url_template: str | None = "https://8.8.8.8/resolve?name={hostname}"
elevation_url_template: str = (
"https://maps.googleapis.com/maps/api/elevation/json?locations={locations}&key={key}"
)
http_accept_language: str = "en"
http_referer: str = "OSMnx Python package (https://github.com/gboeing/osmnx)"
http_user_agent: str = "OSMnx Python package (https://github.com/gboeing/osmnx)"
imgs_folder: str | Path = "./images"
log_console: bool = False
log_file: bool = False
Expand Down
Loading