question

matthewlabo avatar image
0 Votes"
matthewlabo asked IoTGirl edited

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.

azure-mapswindows-maps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IoTGirl avatar image
0 Votes"
IoTGirl answered

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://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IoTGirl avatar image
0 Votes"
IoTGirl answered IoTGirl edited

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

matthewlabo avatar image
0 Votes"
matthewlabo answered

@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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

matthewlabo avatar image
0 Votes"
matthewlabo answered matthewlabo commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Ok, I think the following are possible sources of your issue:

  • The free keys are limited to making 5 requests per second (I believe it's 5 for free). If your code makes more requests than that, some requests will be throttled or blocked.

  • For your waypoints, you are replace spaces with %20, which is a good start to encode the URL parameter, but there are other common characters in addresses that can cause issues (i.e. "1st & main"). This could cause the URL to become invalid, or result in other URL parameters being ignored (like the subscription key). Try using the urllib's urllib.parse.quote method. This will ensure all special characters in the waypoint address are handled correctly.


1 Vote 1 ·

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 the HTTP 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.

0 Votes 0 ·

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.

0 Votes 0 ·
rbrundritt avatar image
0 Votes"
rbrundritt answered
  • 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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.