Select to view content in your preferred language

Stop Start Service Error

287
1
Jump to solution
08-21-2024 12:54 PM
nacelle_pylon
Occasional Contributor

Recently upgraded to Enterprise 10.9.1 from 10.8.1. ArcGIS Pro 3.3.1. The script we have is a maintenance script set up on a virtual machine run by task scheduler that also does stopping and starting of services. Since the upgrade the script has run intermittently and when the script attempts to connect to portal, we we get an error message that says "Error connecting to portal: 'Server' object has no attribute 'services'"

Portion of Script below:

def CreatePortalConnection():
try:
logging.info('Connecting to portal')
gis = GIS(PortalURL, PortalUser, PortalPass)
print(gis)
logging.info('Listing servers')
gis_servers = gis.admin.servers.list()
print(gis_servers)
logging.info('Specifying docking server')
ArcMAP = gis.admin.servers.list()[1]
print(ArcMAP)
ServerFolder = ArcMAP.services.list(Folder)
return ServerFolder
except Exception as e:
logging.error("Error connecting to portal: "+str(e))
print("Error connecting to portal: "+str(e))
print("QUITTING EXECUTION")
email(f'👎 CONNECT TO PORTAL FAILED <br> <br> {LogFile}', "👎")
quit()

def stop_services(ServerFolder):
try:
if StartStop == True:
logging.info(f'Stopping services in {Folder} folder on ARCMAP')
print(f'Stopping services in {Folder} folder on ARCMAP')
for service in ServerFolder:
logging.info("Stopping - " + str(service))
print("Stopping - " + str(service))
service.stop()
else:
logging.info('Stopping services skipped by user input.')
print('Stopping services skipped by user input.')
except Exception as e:
logging.error("Error stopping services: "+str(e))
print("Error stopping services: "+str(e))
print("QUITTING EXECUTION")
email(f'👎 STOP SERVICES FAILED <br> <br> {LogFile}' "👎")
quit()

def start_services(ServerFolder):
try:
if StartStop == True:
logging.info(f'Starting services in {Folder} folder on ARCMAP')
print(f'Starting services in {Folder} folder on ARCMAP')
for service in ServerFolder:
logging.info("Starting - " + str(service))
print("Starting - " + str(service))
service.start()
else:
logging.info('Starting services skipped by user input.')
print('Starting services skipped by user input.')
except Exception as e:
logging.error("Error starting services: "+str(e))
print("Error starting services: "+str(e))
print("QUITTING EXECUTION")
email(f'👎 START SERVICES FAILED <br> <br> {LogFile}' "👎")
quit()

 

 

 

We set the log to debug and got this additional information below (slightly redacted)

 

Connecting to portal: xyzx.xyzxy.xyz
Starting new HTTPS connection (1): xyzx.xyzxy.xyz:443
"GET /portal/info?f=json" 500 1208
"GET /portal/rest/info?f=json" 500 1208
"GET /portal/sharing/rest/info?f=json" 200 134
"GET /portal/rest/services?f=json" 500 1208
Generated new state DBbaHxUjLDuIdPq2DfeQF820Gaw2EG.
"GET /portal/sharing/rest/oauth2/authorize?response_type=token&client_id=pythonapi&redirect_uri=https%3C%2F%2Fxxxx.xyzxy.xyz&state=DBbaHxUjLDuIdPq2DfeQF710Gaw2EG&expiration=600&allow_verification=false&style=dark&locale=en-US" 400 854
Generated new state ublnZvdixx3c1rDdfhZLka5RdLQxtE.
"GET /portal/sharing/rest/oauth2/authorize?response_type=code&client_id=pythonapi&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&state=ublnZvdixx3c1rPpfhZLka7RdLQxtE&expiration=20160&allow_verification=false&style=dark&locale=en-US" 400 854
Generated new state P7HGhgGIDncMUpal0FVNr1NeTb6vRM.
"GET /portal/sharing/rest/oauth2/authorize?response_type=token&client_id=arcgisonline&redirect_uri=https%3A%2F%2Fxxxx.xyzxy.xyz&state=P7HGhgGIDncMUpal0FVNr1NeTb6vRM&expiration=600&allow_verification=false&style=dark&locale=en-US" 200 1897
"POST /portal/sharing/oauth2/signin" 302 0
"POST /portal/sharing/rest/portals/self" 200 4179
"POST /portal/sharing/rest/community/users/portaladmin" 200 4640
"GET /portal/portaladmin?f=json" 302 0
Listing servers
"POST /portal/sharing/rest/portals/self/servers" 200 280
Starting new HTTPS connection (1): xyzx.xyzxy.xyz:6443
"GET /arcgis/rest/services?f=json" 200 1086
Incremented Retry: Retrying connection to xyzx.xyzxy.xyz timed out. (connect timeout=None)
"GET /arcgis/admin?f=json" 302 None
"GET /arcgis/admin/?f=json" 200 219
"GET /arcgis/admin/logs?f.json" 200 49
Resetting dropped connection: xyzx.xyzxy.xyz
"GET /mapping/rest/services?f=json" 200 320
Specifying docking server

Resetting dropped connection: xyzx.xyzxy.xyz
"GET /docking/admin?f.json" 403 7070
ERROR - Error connecting to portal: 'Server' object has no attribute 'services'
EMAIL SENT

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi @nacelle_pylon,

Here is some code I use to stop all services.  May be worth testing with this to see if you get the same error.

 

from arcgis.gis import server

# Variables
serverURL= 'https://ags.esri.com/server'    # ArcGIS Server URL
username = 'portaladmin',
password = 'portal1234'

# Connect to ArcGIS Server
# If ArcGIS Server is federated, use Portal credentials
# If ArcGIS Server is non-federated, use AGS credentials
agsServer = server.Server(url=serverURL, username=username, password=password)

# Create list of folders
folderList = [folder for folder in agsServer.content.folders if folder != 'Hosted'
              and folder != 'System' and folder != 'Utilities']
folderList.append('')

# Stop services
for folder in folderList:
    for service in agsServer.services.list(folder):
        service.stop()

 

 

View solution in original post

0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor

Hi @nacelle_pylon,

Here is some code I use to stop all services.  May be worth testing with this to see if you get the same error.

 

from arcgis.gis import server

# Variables
serverURL= 'https://ags.esri.com/server'    # ArcGIS Server URL
username = 'portaladmin',
password = 'portal1234'

# Connect to ArcGIS Server
# If ArcGIS Server is federated, use Portal credentials
# If ArcGIS Server is non-federated, use AGS credentials
agsServer = server.Server(url=serverURL, username=username, password=password)

# Create list of folders
folderList = [folder for folder in agsServer.content.folders if folder != 'Hosted'
              and folder != 'System' and folder != 'Utilities']
folderList.append('')

# Stop services
for folder in folderList:
    for service in agsServer.services.list(folder):
        service.stop()

 

 

0 Kudos