TypeError: can only concatenate str (not "NoneType") to str

6362
28
Jump to solution
08-15-2022 08:02 AM
ABishop
MVP Regular Contributor

Hello,

I hope this is posted in the right place.  I am troubleshooting a script that I have been running for almost a year now which updates a hosted feature service in ArcGIS Online.  We recently upgraded our ArcMap and Server to 10.8.2 and ArcGIS Pro 3.0.1.  I am wondering if this update has something to do with it?  Anyhow, I have posted the python  code below and attached a pic of the TypeError I receive when I try to run the script from Python 3 IDLE.  Please help. 

import arcpy
import os, sys
from arcgis.gis import GIS

### Start setting variables
# Set the path to the project
prjPath = "I:\\users\\abishop\\PY\\FeatureServiceUpdates\\AgUseParcels\\AgUseParcels.aprx"

# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "Agricultural_Use_Parcels"
portal = "https://mcpafl.maps.arcgis.com/" # Can also reference a local portal
user = "***************"
password = "*************"

# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""

### End setting variables

# Local paths to create temporary content
relPath = sys.path[0]
sddraft = os.path.join(relPath, "AgUseParcels.sddraft")
sd = os.path.join(relPath, "AgUseParcels.sd")

# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS','', True, True)
arcpy.StageService_server(sddraft, sd)

print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
    print("Setting sharing options…")
    fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print("Finished updating: {} – ID: {}".format(fs.title, fs.id))

#provide input to stop script - uncomment input below if you need to see the script final output in the command window
input('Press ENTER to exit') 
Amanda Bishop, GISP
0 Kudos
1 Solution

Accepted Solutions
ABishop
MVP Regular Contributor

Dan and other's who may see this thread.  A good old fashion truncate table and append worked!

Amanda Bishop, GISP

View solution in original post

0 Kudos
28 Replies
DanPatterson
MVP Esteemed Contributor

It mean that either the path or the folder id is returning None.  

Where this occurs depends on whether any of your print statements are even reached.


... sort of retired...
ABishop
MVP Regular Contributor

Hello Dan,

Thank you for replying.  Yes, it says line 49 in the actual script which is calling out the sdItem.update(data=sd) module.  Any chance this changed with our upgrade?

Amanda Bishop, GISP
0 Kudos
DanPatterson
MVP Esteemed Contributor

That gets a bit difficult since you are using the arcgis module which is now at 2.0.1 and you would have to examine their help topics

API Reference for the ArcGIS API for Python | ArcGIS API for Python

maybe

arcgis.gis module | ArcGIS API for Python with a lot of scrolling under "item", but I don't do portal stuff, so I can't help more.


... sort of retired...
ABishop
MVP Regular Contributor

I'm still trying to determine why the code works for one feature service but not another?

Amanda Bishop, GISP
0 Kudos
DanPatterson
MVP Esteemed Contributor

That is beyond my domain... things get "cloudy" for me when you talk feature service 😉  Tech Support perhaps.


... sort of retired...
ABishop
MVP Regular Contributor

Ok thank you

Amanda Bishop, GISP
0 Kudos
ABishop
MVP Regular Contributor

Dan and other's who may see this thread.  A good old fashion truncate table and append worked!

Amanda Bishop, GISP
0 Kudos
BrianPangtay
Occasional Contributor

Did you truncate/append the source data you were trying to push to AGO? Meaning there was something wrong with the source data... 

0 Kudos
ABishop
MVP Regular Contributor

Hello Brian,

I don't understand your question.  I truncated and appended the data in AGO with the source data from my PC.

Amanda Bishop, GISP
0 Kudos