[ Why python Phonenumbers library give null for country of +358*****? ]
I use the below code to get the country of phone number and I currently use
query = phonenumbers.parse(number, None) geocoder.country_name_for_number(query, "en")
It gives error for numbers with
+358. The library version I tested was the latest:
Anyone has a solution or workaround with this library? The country should be
EDIT1: For example the below number gives an empty string:
>>> number = '+358753263000' >>> query = phonenumbers.parse(number, None) >>> geocoder.country_name_for_number(query, "en") u''
You may have overmasked it. As @Barmar pointed out, according to Wikipedia, the numbers after the '+358' the next number should be 9 (or 0).
>>> geocoder.country_name_for_number(phonenumbers.parse('+358753263000'), 'en') u'' >>> geocoder.country_name_for_number(phonenumbers.parse('+358953263000'), 'en') u'Finland'
Changing that first number from
9 gives Finland. You also have too many digits but it doesn't seem to mind.
I think the problem is that the prefix
+358 is ambiguous. You can see that if you call
>>> geocoder.region_codes_for_country_code(358) ('FI', 'AX')
+358 is the prefix both for Finland and for the Åland Islands (AX).
If a code is ambiguous,
country_name_for_number then checks all of the regions and calls
is_valid_number_for_region for the specific number. If it finds that the number is valid in more than one region, it returns an empty string.
I have opened an issue on their
In case there was an answer, I would post it here later on.