I am trying to use python for address verification using CDYNE service.
I used this as reference to create POST request and it looks like following
import urllib2
import urllib
url = 'http://pav3.cdyne.com/PavService.svc/VerifyAddressAdvanced'
data = {}
data['CityName'] = 'San Francisco'
data['FirmOrRecipient'] = 'CDYNE'
data['LicenseKey'] = 'valid_key'
data['PrimaryAddressLine'] = '45 fremont street'
data['ReturnCaseSensitive'] = True
data['ReturnCensusInfo'] = True
data['ReturnCityAbbreviation'] = True
data['ReturnGeoLocation'] = True
data['ReturnLegislativeInfo'] = True
data['ReturnMailingIndustryInfo'] = True
data['ReturnResidentialIndicator'] = True
data['ReturnStreetAbbreviated'] = True
data['SecondaryAddressLine'] = ''
data['State'] = 'CA'
data['Urbanization'] = ''
data['ZipCode'] = '94105'
and post the request as following
data_encoded = urllib.urlencode(data)
req = urllib2.Request(url, data_encoded)
response = urllib2.urlopen(req)
I see error as
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 398, in open
response = meth(req, response)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 511, in http_response
'http', request, response, code, msg, hdrs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 436, in error
return self._call_chain(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 370, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 519, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
I am new to this so don’t understand what has gone wrong, please help
you either have to send the request as
jsonorxmlformatted document, the schema is on the page you’ve linked to.you’re sending an urlencoded request, which isn’t supported by the api.
edit: that’s how it would look like using
JSON: