dev.virtualearth GET request succeeds in browser but returns empty JSON string in a program

Mike Landis 21 Reputation points
2023-05-29T14:41:01.5033333+00:00
  1. This question is NOT about the Windows API, but no other category comes close and https://answers.microsoft.com/en-us/bing/forum/all/bing-maps-rest-location-api-not-returning-address/cc8fdec9-e891-42f0-ae26-99eb2245c0ec?correlationid=126082de-67a1-49ff-8b9a-eae70a7213b0&from=ContactUsWebBCQR referred me here.
  2. NONE of the tags I could come up with would allow me to post a question, hence Windows API as the tag.
  3. Finally, ... I have a small Python program that submits a well-formed GET request to dev.virtualearth.net with a home address and a Bing Maps API key. It works as expected in a browser, but returns an empty 200 response from the program. What am I not accounting for in the program? Are non-browser GET requests blocked somehow? What's the 'right' way to get the valid JSON I got in a browser into a string in the program?
Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
653 questions
Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
253 questions
{count} votes

2 answers

Sort by: Most helpful
  1. rbrundritt 16,456 Reputation points Microsoft Employee
    2023-05-30T15:20:24.42+00:00

    When in Python, use module like requests to make the REST API call. Here is an example that calls the Location API using a query:

    import requests
    
    x = requests.get('http://dev.virtualearth.net/REST/v1/Locations', params = { 
        "query": "1 Microsoft Way, Redmond, WA 98052",
        "key": "<Your Bing Maps Key>",
        "o": "json"
    })
    
    print(x.json())
    

    Be sure to add your Bing Maps key where is says <Your Bing Maps Key>

    1 person found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more