Accessing USGS Web Service Using Python

D

Doug Caldwell

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:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<searchName xmlns="http://gisdata.usgs.net/XMLWebServices/">
<PlaceName>Alexandria</PlaceName>
<PlaceType>ppl</PlaceType>
<inNumRecords>10</inNumRecords>
<inFirstRecord>1</inFirstRecord>
</searchName>
</soap:Body>
</soap:Envelope>"""

# send request
h = httplib.HTTP('gisdata.usgs.net')
h.putrequest("POST", "/XMLWebServices/TNM_Gazetteer_Service.asmx HTTP/1.1")
h.putheader("Content-Type", "text/xml; charset=utf-8")
h.putheader("Content-Length", str(len(soapstr)))
h.putheader ("SOAPAction",
"http://gisdata.usgs.net/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().read()
print result
---------------

Here is the guidance from the USGS Web Site
http://gisdata.usgs.net/XMLWebServices/TNM_Gazetteer_Service.asmx?op=searchName

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

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

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<searchName xmlns="http://gisdata.usgs.net/XMLWebServices/">
<PlaceName>string</PlaceName>
<PlaceType>string</PlaceType>
<inNumRecords>string</inNumRecords>
<inFirstRecord>string</inFirstRecord>
</searchName>
</soap:Body>
</soap:Envelope>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top