'None' returned from .layers with API

996
2
Jump to solution
02-06-2021 07:28 AM
JasonJordan00
Occasional Contributor

I've done this successfully on a dozen different scripts with other feature layers however this one is causing me issues. After logging into portal with the Python API, I get the item I am working with.

port_item = gis.content.get('#############')

That returns the appropriate item. Then I will grab the point layer.

item_layers = port_item.layers

That, however, returns 'None'.

I've compared with other feature layers that it has worked fine on and I can't find any differences that would cause it to fail. Everything is a hosted feature service, everything is either points or polygons, and just switching out the itemID will successfully return other layers so I know there's not a typo or portal issue.

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

I don't suppose the layer in question is public so that others could attempt to replicate the issue? The only time I've been able to get layers to return 'None' is when the service in question is a hosted table with no features, but as you say, that does not apply to your particular item.

Sight unseen, I would have to assume that there is something different about the item itself. Are you able to access other classes, like manager?

Alternately, if you instantiate the service using arcgis.features.FeatureLayerCollection and the service URL as opposed to the item ID, does the issue persist?

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

I don't suppose the layer in question is public so that others could attempt to replicate the issue? The only time I've been able to get layers to return 'None' is when the service in question is a hosted table with no features, but as you say, that does not apply to your particular item.

Sight unseen, I would have to assume that there is something different about the item itself. Are you able to access other classes, like manager?

Alternately, if you instantiate the service using arcgis.features.FeatureLayerCollection and the service URL as opposed to the item ID, does the issue persist?

- Josh Carlson
Kendall County GIS
JasonJordan00
Occasional Contributor

Using the FeatureLayerCollection method got it to return a token error message that pointed me to a step that slipped my mind. Our portal is behind a firewall so nothing is able to go public, but I forgot to share the layer publicly anyway so it doesn't look for a token (which our authorization methods doesn't easily generate through Python). That's what I've had to do for all other feature services I've used the API on, just plumb forgot to do it this time.