Sample Python Code

Please note: Sample code is Python 3.3. Samples for earlier versions of Python are not yet available

# To make our lives easier when sending/receiving data from a web service
# we'll use the requests library from python-requests.org
# This library provides a much simpler API for sending and receiving data
# than the native urllib API from Python itself.
import requests

# Setup the payload here. The structure of the payload itself will obviously
# change depending on which method/dataset combination we call and what
# parameters that method/dataset combination requires.
# Note that unlike C# and PHP, we do not prefix the XML with the POST key of apirequest=
# because in true pythonic fashion, the request library requires name/value pairs to be
# sent to it in a dictionary

xml = """<?xml version="1.0" encoding="UTF-8" ?> <data>
    <auth>
        <loginname>your_api_username</loginname>
        <key>your_api_key</key>
    </auth>
    <request>
        <dataset>N</dataset>
        <method>getGeoIDByCoord</method>
        <count>false</count>
        <returnType>xml</returnType>
        <returnGeoType>wkt</returnGeoType>
        <parameters>
            <lat>40.713734</lat>
            <lon>-74.011683</lon>
            <submatch>N</submatch>
        </parameters>
    </request>
</data>""";

# form the dictionary payload here
payload = {'apirequest':xml}

# set the content type
headers = {'Content-Type': 'application/x-www-form-urlencoded'}

# make the request and assign the return data
returnData = requests.post('https://api.maponics.com/interface/', data=payload, headers=headers)

# The actual XML (or JSON) data is contained within returnData.text and you can now process it
# For the purposes of this sample, we'll just dump the raw text to the screen
requestOutput = returnData.text print (sRequestOutput)