Hi,
I have a script that downloads data from an ArcGIS item, then loads it into our central database for reporting purposes. It used to work, but early last year it stopped working for some reason. Now when I try to get the data from a gis item it returns {}, even though I know there is data.
Basically this is what the start of the code looks like:
from arcgis.gis import GIS
gis = GIS(username='****', password='****')
item = gis.content.get('426435c937df4661b32b617e4705d003')
item_data = item.get_data()
This isn't actually the item I am trying to get the data from, but this is publicly facing, and I know there are over 1200 records in it so I thought it might work for testing. I have tried multiple items and get the same result for all of them.
Any advice on how to fix this?
Solved! Go to Solution.
Turns out there were a couple of issues going on. The biggest one was that a security certificate on our server expired and when they generated the new one (I know nothing about that process) it somehow stopped the process receiving data. It was weird that it would allow the requests through and I did get empty returns, but when I run a modified script it now runs.
But I have also implemented the ideas above as there were still some issues the way I had been doing it, and those changes fixed it for me.
Thanks Glen
Hello Harry,
Not sure how useful this is, but I had something similar occur recently but related to being unable to access WebMaps from AGOL.
Long story short, in order to get my scripts to work again, I needed to install an older version of ArcGIS Pro (I think pre-3.3?) to be able to get access to those WebMaps again so I could update them and make them usable with the 3.4 and the current AGOL libraries.
Just passing this along because "It used to work, but early last year it stopped working for some reason." is exactly what happened to me. I contacted Esri Support about it at the time and they suggested the workaround above so I could do the upgrades to the WebMaps so my scripts would work again.
Good luck!
Joanne
Thanks Joanne,
We are still on ArcGIS Pro 3.2.2 so I don't think that will be the issue, but I might just onto a different PC with an older version and see if I get the same issue.
Thanks
Unfortunately I got the same result using 3.1, and I'm sure we were using at least that version when it was last working.
Hi @HarrySmiles,
get_data() for an Item object doesn't actually return data from records or features, even if you have 1200 records in a Feature Layer in a Feature Service you cannot access them via the get_data() method.
For example, get_data(), from what I remember, used to return an empty list (or dictionary), as of the ArcGIS API for Python version 2.4.0, which ships with ArcGIS Pro 3.4, it now returns a dictionary containing the layers and tables definitions (symbology, fieldInfos etc) for the Feature Service, but no attribute/geometry information.
When using get_data() on a WebMap Item, it returns the JSON definition of the WebMap as dictionary and defined by the WebMap specification here.
For a Dashboard Item, get_data() will return information about the layout and widgets used.
Using get_data() on a CSV item will download the CSV to C:\Users\******\AppData\Local\Temp, and you can access as you would any other CSV file.
The get_data() method for an Item object will return something diffeferent (or nothing) for different Content Item Types.
You cannot use get_data() to get actual data like attributes and geometry, it never had this functionality.
I hope that helps.
Glen
Hi Glen,
You're right, get_data() doesn't actually return the data I'm after but, I use it to determine which layer to pick up from the service. As it returns nothing I'm unable to then move to the next part of my code which looks like this:
Hi @HarrySmiles,
I would use the Item object type (item.type) instead, if it is a Feature Service (type: Feature Layer Collection), then continue to access the Feature Layers (and Tables) and then perform the data extraction. No need for the get_data() method for the workflow. You could add a check to see if the item has any layer or tables, but it would be very rare your have a feature service without one of these.
This below would also suit.
if len(item.layers) > 0:
# access the layer(s)
# extract the data
Turns out there were a couple of issues going on. The biggest one was that a security certificate on our server expired and when they generated the new one (I know nothing about that process) it somehow stopped the process receiving data. It was weird that it would allow the requests through and I did get empty returns, but when I run a modified script it now runs.
But I have also implemented the ideas above as there were still some issues the way I had been doing it, and those changes fixed it for me.
Thanks Glen