Select to view content in your preferred language

Use this Python script to get a 15 minute break whenever you need one.

545
2
04-06-2023 04:51 PM
Labels (3)
Brian_Wilson
Regular Contributor II

If you run this code it will lock you out of your Enterprise account for 15 minutes.

 

import arcpy
try:
    result = arcpy.server.StageService("Roads.sddraft", "Roads_hosted.sd")
except Exception as e:
    print(e)

 

The output will look like this.

 

ERROR 001272: Analyzer errors were encountered ([{"code":"00102","message":"Map does not contain a required layer type for Map Service","object":"Roads"}]).
Failed to execute (StageService).

 

The error message is wrong. The map is fine. But at this point if you try to connect to your Portal you get something like this,

 

from arcgis.gis import GIS
try:
    gis = GIS("https://delta.co.clatsop.or.us/portal", profile='brian')
except Exception as e:
    print(e)

Unable to generate token.
Too many invalid logins. Please try again later.
(Error Code: 400)

 

You will not be able to access your Enterprise server from either Pro or a web browser (or your Python scripts) for 15 minutes. (Need I say that the credentials are perfect? That is not relevant.)

I hear you ask "what is in that sddraft file that is so dangerous? I want one too!"

Ha! That could be a closely held secret, that I would be reluctant to share, but you deserve breaks too! I mean think of it. I had to test, wait 15 minute, test, wait,... until I hit the correct random meaningless unrelated line of code. (Yes-- I put in a support ticket asking how to clear the 15 timer or REMOVE it but have not heard back yet.)

Okay, my secret! In setting up the sddraft, I set the wrong value for the property "federatedServerUrl" I gave it a reference to an AGS connection file instead of the Url. I'd think this would result in an HTTP GET error, wouldn't you?

But it completely blew me out of the water (in 15 minute increments) even though the "StageService" method is just supposed to test your SDdraft for mistakes and then repackage it into an SD file ready for upload.

There you go! Your ticket to lots of breaks!!  Enjoy!

0 Kudos
2 Replies
Brian_Wilson
Regular Contributor II

If I learn how to clear the 15 minute timer (or avoid tripping it) I will post it here as the solution.

 

0 Kudos
Brian_Wilson
Regular Contributor II

I learned I can shorten up the timeouts on how long a token is valid, but that does not help if I have been issued an invalid token.

Best I think would be for the server to stop issuing invalid tokens when it hits a bug.

I have never tried to use tokens for authentication. Because of the bug I am hitting here I learned how to use Windows profiles, as shown on line 3 of the code above.

In this case, I never explicitly request authentication, I simply hand an AGS file to the Python API.

Ultimately the answer is "don't hand bad arguments to Esri" because it's apparent after years of working with their code that they don't put enough effort into handling errors.

 

0 Kudos