In [1]:
#https://github.com/goodalljl/hydroinformatics_class/blob/master/Class21_NHDGeocoder.py
from urllib.request import urlopen
import json
from pprint import pprint

#input by user
Name = "Ivy Creek"
State = "VA"

#build URL
url = "http://ofmpub.epa.gov/waters10/Name.Service?" \
    + "pFullText=" + Name.replace(' ', '+') \
    + "&pFullTextRegex=" \
    + "&pBasename=" \
    + "&pBasenameRegex=" \
    + "&pHydrography=" \
    + "&pHydrographyRegex=" \
    + "&pDirectional=" \
    + "&pDirectionalRegex=" \
    + "&pOperator=EQ" \
    + "&pQueryLimit=" \
    + "&pJWThreshold=90" \
    + "&pResolution=3" \
    + "&pSourceTable=" \
    + "&pState=" + State \
    + "&pStateMod=%2C" \
    + "&pCountyFips5=" \
    + "&pCountyFips5Mod=%2C" \
    + "&pSubbasin=" \
    + "&pSubbasinMod=%2C" \
    + "&pGnisClass=" \
    + "&pGnisClassMod=%2C" \
    + "&pFtype=" \
    + "&pBreakBySubbasin=false" \
    + "&pBreakByFcode=false" \
    + "&optNHDPlusDataset=2.1" \
    + "&optCache=1415283785917" \
    + "&optJSONPCallback=" \

#load response into JSON object
f = urlopen(url)
response = json.loads(f.read().decode())

#uncomment to see structure of response
#pprint(response)

#get lat and lon coordinates of centroid
print("{} result(s) found".format(len(response['output']['results'])))

#there may be multiple responses if it is a common stream/river/waterbody name
lats = []
lons = []
for i in range(0, len(response['output']['results'])):
    coords = response['output']['results'][i]['gnis_centroid_geom']['coordinates']
    lon = coords[0]
    lat = coords[1]
    lats.append(lat)
    lons.append(lon)
    print("Pt {}: The centroid point is {}, {}".format(i, lat, lon))


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5778c32852f6> in <module>()
      1 #https://github.com/goodalljl/hydroinformatics_class/blob/master/Class21_NHDGeocoder.py
----> 2 from urllib.request import urlopen
      3 import json
      4 from pprint import pprint
      5 

ImportError: No module named request