I'm running a simple python script from arcmap that sends an html post and processes the response. This script runs just fine from pythonwin but for some reason I receive the following error when running the script from an arcmap toolbox: AttributeError: 'NoneType' object has no attribute 'split'
The python code and stack trace is below. I'm stumped why it would run outside of arcmap but not within. I'm sure it's something simple I'm missing. Hopefully someone can point it out. 🙂
for row in cursor:
arcpy.SetProgressorLabel("Loading {0}...".format(row))
url = "https://myurl.com"
payload = "streetAddress="+row[0]+"&city="+row[1]+"&state="+row[2]+"&zip="+row[3]+"&apikey="+apikey+"&format=csv&census=false&censusYear=2000|2010¬Store=false&version=4.01"
headers = {
'accept': "application/x-www-form-urlencoded",
'content-type': "application/x-www-form-urlencoded",
'access-control-allow-origin': "*"
}
response = requests.request("POST", url, data=payload, headers=headers)
responseList = response.text.split(',')
StackTrace:
Traceback (most recent call last):
File "C:\Development\PythonAddins\TAMUGeocoder.py", line 75, in <module>
response = requests.request("POST", url, data=payload, headers=headers)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 456, in request
prep = self.prepare_request(req)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\sessions.py", line 389, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\models.py", line 293, in prepare
self.prepare_url(url, params)
File "C:\Python27\ArcGIS10.1\lib\site-packages\requests\models.py", line 362, in prepare_url
host = host.encode('idna').decode('utf-8')
File "C:\Python27\ArcGIS10.1\Lib\encodings\idna.py", line 157, in encode
labels = dots.split(input)
AttributeError: 'NoneType' object has no attribute 'split'
Best Answer
The error
often indicates that the attribute you are trying to split is
Null
, meaning there is no value in it to split.You need to check the attribute is not Null before splitting. Something like