1

I'm trying to get started with the Bing dataflow API called from Python to batch geocode addresses. For simplicity, I'm using csv input format. I've consistently encountered a 400 status code, "One or more parameters are not valid." To try to get a working example, I'm using Microsoft's sample csv input data copied directly from the docs (web page: Geocode Dataflow Sample Input and Output Data Version 2.0). Here is my test code:

def _testApiCall():
    payload = "Bing Spatial Data Services, 2.0\n" 
    payload += "Id, GeocodeRequest/Culture, *plus the rest of the long line of field names*"
    payload += "1,en-US,,One Microsoft Way,WA,,,,Redmond,98052\n" 
    payload += "3,en-US,One Microsoft Way, Redmond, Wa\n" 
    payload += "4,en-gb"

    url = f"https://spatial.virtualearth.net/REST/v1/dataflows/geocode?input=csv&output=json&key={bingMapsKey}"

    response = requests.post(url, data=payload.encode('utf-8'))
    with open("response.json", "w") as response_file:
        json.dump(response.json(), response_file, indent=4)

the response file always contains:

{
    "authenticationResultCode": "ValidCredentials",
    "brandLogoUri": ...,
    "copyright": ...,
    "errorDetails": [
        "One or more parameters are not valid.",
        ": The data uploaded in this request was missing or invalid."
    ],
    "resourceSets": [],
    "statusCode": 400,
    "statusDescription": "Bad Request",
    "traceId": "a45bd0371d8e4a55b5e415305710ef80|BN00006676|0.0.0.0"
}

Can't figure out what I'm doing wrong, or what parameters it's referring to.

I've reduced the code to the bare minimum for the call, and replicated MS's sample data. My API key is validated so apparently the URL is basically OK. Was expecting the normal result with a job ID and links to download data. Can't seem to get beyond this status 400 failure. What am i missing? Thanks.

1 Answer 1

1

Issue was missing Content-Type header spec in the requests.post()

Sign up to request clarification or add additional context in comments.

2 Comments

What Content-Type header did you use? text/csv?
text/plain, as per the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.