Update tomtom.py for correct address encoding #598
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix TomTom geocoder: fully URL-encode the query (including "/") to prevent 404 errors on valid addresses
Summary
The current implementation of the TomTom geocoder in
geopydoes not fully URL-encode the geocoding query.It uses:
However,
urllib.parse.quote()usessafe='/'by default, meaning the slash character is not encoded.This leads to URLs such as:
TomTom interprets
/as a path separator, not as part of the address string, which results in:5/1,12/3,31/29)Such address formats are extremely common in Russia, Poland, Czech Republic and many other countries.
Fix
Replace:
with:
This ensures all characters are encoded — including
/.Example:
Resulting in a correct TomTom URL:
TomTom handles this correctly and returns proper geocoding results.
Examples of correct vs. incorrect URLs
1. Address: “Москва, Красная площадь, 1” (no slash)
Both current and fixed implementations encode this correctly.
Current geopy:
Proposed encoding:
(same result)
2. Address: “Москва, Никольская улица, 5/1с1” (problem case)
🔴 Current geopy (incorrect)
Slash is not encoded → treated as path separator:
TomTom interprets this as:
/5/1с1.json→ 404 Not Found
🟢 With fix (correct)
TomTom returns valid results.
Patch (diff)