Bing Maps: Unauthorized/Not Found

Matthew Labo 21 Reputation points
2021-06-22T17:22:20.51+00:00

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.

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
736 questions
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
257 questions
0 comments No comments
{count} votes

Accepted answer
  1. IoTGirl 3,206 Reputation points Microsoft Employee
    2021-06-25T07:22:52.247+00:00

    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.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. rbrundritt 18,686 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.
    0 comments No comments

  2. Matthew Labo 21 Reputation points
    2021-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.


  3. Matthew Labo 21 Reputation points
    2021-06-24T12:16:49.26+00:00

    @IoTGirl
    URL passed (minus API key): http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml&wp.0=1051%20Rue%20Hammer%20Rd%2C%20Cedar%20Grove%2C%20Tennessee%2C%2038321&wp.1=11%20MEDICAL%20PARK%20COURT%2C%20JACKSON%2C%20TN%20383059998&avoid=minimizeTolls&distanceUnit=mi&key=***

    Response:
    <StatusCode>404</StatusCode>
    <StatusDescription>Not Found</StatusDescription>
    <AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
    <ErrorDetails>One or more locations specified in the waypoint parameter are invalid or require more information.</ErrorDetails>
    <ErrorDetails>1051 Rue Hammer Rd, Cedar Grove, Tennessee, 38321</ErrorDetails>
    <TraceId>0168793eb556402287226dbba645fd0c|BN000021CD|0.0.0.0|Ref A: 247DBA5AC4DA4D2B8D7D722544BC270E Ref B: BN3EDGE0805 Ref C: 2021-06-24T11:58:30Z|Ref A: 23658FA7A6EC4D7C9F7D6290F81E47D1 Ref B: BN3EDGE0617 Ref C: 2021-06-24T11:58:30Z</TraceId>

    Web: https://www.bing.com/maps?q=1051+Rue+Hammer+Rd%2c+Cedar+Grove%2c+Tennessee%2c+38321

    0 comments No comments

  4. IoTGirl 3,206 Reputation points Microsoft Employee
    2021-07-30T16:32:39.78+00:00

    The team has updated the result for the one address on Hammer Rd noted in your call. These updates are tested and then pushed live so the turn around time is not fast but the data is well validated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.