Exact error: Unable to reach the server where the service is. Consider using calling deleteItem with options = { 'force' : true } if the server won't be available anymore.
The issue usually occurs when Portal for ArcGIS is unfederated and re-federated or when some configuration changes are made to Portal for ArcGIS.
import arcgis
from arcgis.gis import GIS
gis = GIS("https://portalname/arcgis", "username", "password")
delete_orphaned_items = gis.content.search(query="owner: ownername AND title:*title*", item_type='Feature *', max_items=100)
delete_orphaned_items
filtered_items = [item for item in delete_orphaned_items if 'title' in item.title]
print(len(filtered_items))
sorted(filtered_items, key=lambda x:x.title)
for item in filtered_items:
try:
item.delete(dry_run=True)
except TypeError:
print(f'{item.title} not deleted')
except RuntimeError:
print(f'{item.title} not deleted')
Delete an item in Portal for ArcGIS using arcgis.gis module: https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.gis.toc.html#item