Select to view content in your preferred language

How to Use Previous Version of ArcGIS API for Python

650
8
09-10-2024 02:15 PM
Map12
by
Emerging Contributor

Is it possible to use a previous version of the ArcGIS API for Python without reverting ArcGIS Pro to a previous version?

I have a script that works great with the ArcGIS Pro 3.0 conda environment. Once I upgraded to ArcGIS Pro 3.3 it no longer works. Specifically here is the code and error below:

AttributeError: 'Server' object has no attribute 'services'

from arcgis.gis.server import Server
gis_server = Server(url=f"{server_base_url}/arcgis/admin",
                  token_url=f"{server_base_url}/arcgis/tokens/generateToken",
                  username=username,
                  password=password)
folder_list = gis_server.services.folders

Again, this works fine in Pro 3.0 but not 3.3.

I also use VScode to run scripts. I have tried exporting the 3.0 conda environment as a .yml file and bringing it into my new machine to no avail.

Also the package manager in Pro does not allow you to change versions of arcgis (the package for ArcGIS API for Python).

My script needs arcpy so I don't believe I could create a new blank virtual environment and add the packages I need.

 

0 Kudos
8 Replies
DanPatterson
MVP Esteemed Contributor

should someone from the api team not see this, then you might want to post an "issue" on

Esri/arcgis-python-api: Documentation and samples for ArcGIS API for Python (github.com)

if you can see if it has already been address in the "issues" "closed" or "pull requests" sections of their github site

And, you would have to uninstall the current version and install the previous version since you can't have both package versions installed at the same time


... sort of retired...
0 Kudos
zkovacs
Frequent Contributor

I presume that the above code worked with a previous version of ArcGIS Enterprise, and you have also upgraded that alongside your Pro deployment?

I just had a quick look at the reference (https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html) and the Server object does not have a folders property, hence the error. To be able to list your services folders on your server, you should be using the ServicesDirectory class instead as this has the desired folders property.

Your code would look something like this:

 

from arcgis.gis.server.catalog import ServicesDirectory
SD = ServicesDirectory(url="", username="", password="")
SD.folders

 

Where url is {serverurl/webadaptor} - eg. https://someserver.com/arcgis . 

I just tested this in Pro 3.3 with Enterprise 11.1 and it works like a charm. Hope this helps.

(NB: don't embed user/pass in your code as it is bad practice. Store them in your user profile/credential store, or at least use password hashes. If you have Single-Sign-On with an IDP enabled in your Enterprise, you should be able to use OAuth with a client id to log in to your server/portal.)

0 Kudos
Map12
by
Emerging Contributor

Thank you @zkovacs . I implemented your code update and can connect to server with ServicesDirectory. Unfortunately I receive a KeyError: 'folders' error when trying to get the list of folders.

You mentioned upgrading Enterprise but that is not feasible at this time and we are at a standalone server 10.7.1

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@Map12 does the following work:

from arcgis.gis import server

# Stand-alone ArcGIS Server instance specify PSA account
# Federated ArcGIS Server instance specify Portal Admin account
agsServer = server.Server(url="https://ags.esri.com/server", username='siteadmin', password='siteadmin')
print(agsServer.content.folders)
0 Kudos
Map12
by
Emerging Contributor

Hi Jake, Thanks for your reply. Here's what I got. Your method did properly acquire the server object but no luck on folders.

KeyError: 'folders'

0 Kudos
zkovacs
Frequent Contributor

Oh, I didn't know your server was at 10.7.1. I don't think it will be possible to do what you want with Pro 3.3 then...

Esri Support should be able to confirm that though, so log a ticket with them.

0 Kudos
Map12
by
Emerging Contributor

Is there anything that shows compatibility between the arcgis library and Server versions?

Something along the lines of arcgis 2.0.1 (Pro 3.0) has full compatibility with Server 10.7.1 but arcgis 2.3.0 (Pro 3.3) does not.

0 Kudos
zkovacs
Frequent Contributor

I haven't been able to find anything on that unfortunately, but Tech Support should be able to confirm it.

0 Kudos