The answer is correct. The driving directions could not route to that address as it is actually not in our data so it will need to be validated with a civic authority in order to be added. You should be able to use the same advice I gave at https://learn.microsoft.com/en-us/answers/questions/435344/bing-maps-rest-api-no-route-was-found-for-the-wayp.html to get the Bing Maps consumer experience. Get the routable co-ordinate(s) first, then call the directions API.
Bing Maps: Unauthorized/Not Found

Hello,
Running a Python script through the REST API and in 1,052 address pair lookups, I get 1,047 positive results (aka it properly returned the drive time/distance I was looking for). However, in several cases (2x HTTP Error 404: Not Found; 3x HTTP Error 401: Unauthorized) I get errors. New to the Bing Maps API and not sure why I'd be getting a handful of errors in these address pairs, but none of the others. Manually entering these 5 address pairs into Bing Maps via a web browser returns results as expected, so it does not appear to be that Bing can't recognize the address.
Any ideas on how to address these errors would be appreciated. Thanks.
-
4 additional answers
Sort by: Most helpful
-
rbrundritt 7,251 Reputation points Microsoft Employee
2021-06-22T19:20:14.057+00:00 - Can you provide examples of the queries that are failing?
- What library are you using or how are you using Bing Maps in Python?
- What type of Bing Maps key are you using? Enterprise, free?
- Are you making these requests all at once? If so, it's possible that you are hitting the max queries per second limits.
Matthew Labo 21 Reputation points2021-06-22T21:11:16.617+00:00 Can you provide examples of the queries that are failing?
Function in use:
def read_api(claim_key, addressFrom, addressTo): api_key = 'removedhere-usingFreeKey' base = 'http://dev.virtualearth.net/REST/V1/Routes/Driving' location1 = addressFrom.replace(' ', '%20') location2 = addressTo.replace(' ', '%20') url = '{}?o=xml&wp.0={}&wp.1={}&avoid=minimizeTolls&distanceUnit=mi&key={}'.format(base, location1, location2, api_key) read_url = urllib.request.urlopen(url).read() data = bs4.BeautifulSoup(read_url,'xml') drive_dist = float(data.find('TravelDistance').text) drive_time = float(data.find('TravelDuration').text) / 60 # Convert time from seconds to minutes return [claim_key, drive_dist, drive_time]
Loop in use:
for index, row in df.iterrows(): NaN_dist = np.isnan(row[2]) NaN_time = np.isnan(row[3]) if (NaN_dist==True) or (NaN_time==True): try: drive_info = read_api(index, row[0], row[1]) df.at[index, 'drive_distance'] = drive_info[1] df.at[index, 'drive_time'] = drive_info[2] writes += 1 except BaseException as error: errors += 1 error_list.append([index, error, row[0], row[1]]) continue else: skips += 1 continue
What library are you using or how are you using Bing Maps in Python?
import urllib.request import pandas as pd import numpy as np import bs4 as bs4
What type of Bing Maps key are you using? Enterprise, free?
- Free
Are you making these requests all at once? If so, it's possible that you are hitting the max queries per second limits.
- Yes, looping through a list of addresses. I do not believe that I'm hitting a max queries per second as the same list items consistently fail with the same errors - even when run individually.
Thanks.
-
Thanks, @rbrundritt .
To your points,
timeit
is showing an average query speed of ~0.8 seconds/query, so should be well under the limit. Also,urllib.parse.quote
helped in that is caught all of theHTTP Error 401: Unauthorized
errors, but still encounters some (2x)HTTP Error 404: Not Found
errors. The addresses don't seem to be problematic (e.g. 1 MEDICAL CENTER PHARMACY, MORGANTOWN, WV 26506). Still investigating these outliers, so any additional tips are welcomed.You should get a Transaction/Trace ID that we can trace that should align with the exact call. We see your template but not the exact call so we can't tell you exactly the issue unless we see the call itself and the error in the response.