Accessing USGS Web Service Using Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug Caldwell

    #1

    Accessing USGS Web Service Using Python

    Hi!

    ** Accessing the USGS Web Service Using Python **

    I am trying to access the US Geological Survey's gazetteer SOAP web service
    using Python to find the locations of all the places with the name
    'Alexandria.' I tried to keep this simple by putting a soap message in a
    string and sending the request using httplib.

    I am receiving the following error message.

    Reply: 400 Bad Request
    <h1>Bad Request</h1>
    `
    I apologize in advance if this is not the correct approach.

    --------------------------
    Here is my code ...

    import httplib

    # soap string to send
    soapstr = """<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelop e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/">
    <soap:Body>
    <searchName xmlns="http://gisdata.usgs.ne t/XMLWebServices/">
    <PlaceName>Alex andria</PlaceName>
    <PlaceType>pp l</PlaceType>
    <inNumRecords>1 0</inNumRecords>
    <inFirstRecord> 1</inFirstRecord>
    </searchName>
    </soap:Body>
    </soap:Envelope>" ""

    # send request
    h = httplib.HTTP('g isdata.usgs.net ')
    h.putrequest("P OST", "/XMLWebServices/TNM_Gazetteer_S ervice.asmx HTTP/1.1")
    h.putheader("Co ntent-Type", "text/xml; charset=utf-8")
    h.putheader("Co ntent-Length", str(len(soapstr )))
    h.putheader ("SOAPAction ",
    "http://gisdata.usgs.ne t/XMLWebServices/searchName")
    h.endheaders()
    # send soap string
    h.send(soapstr)

    # get the HTTP response
    reply, message, headers = h.getreply()
    print "Reply: ", reply, message
    # print the results
    result = h.getfile().rea d()
    print result
    ---------------

    Here is the guidance from the USGS Web Site


    The following is a sample SOAP request. The placeholders shown need to be
    replaced with actual values.

    POST /XMLWebServices/TNM_Gazetteer_S ervice.asmx HTTP/1.1
    Host: gisdata.usgs.ne t
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://gisdata.usgs.ne t/XMLWebServices/searchName"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelop e xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/">
    <soap:Body>
    <searchName xmlns="http://gisdata.usgs.ne t/XMLWebServices/">
    <PlaceName>stri ng</PlaceName>
    <PlaceType>stri ng</PlaceType>
    <inNumRecords>s tring</inNumRecords>
    <inFirstRecord> string</inFirstRecord>
    </searchName>
    </soap:Body>
    </soap:Envelope>

    ---------------

    Thank you!


Working...