<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Stop Start Service Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stop-start-service-error/m-p/1526388#M71302</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/435000"&gt;@nacelle_pylon&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Here is some code I use to stop all services.&amp;nbsp; May be worth testing with this to see if you get the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Aug 2024 13:28:39 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-08-23T13:28:39Z</dc:date>
    <item>
      <title>Stop Start Service Error</title>
      <link>https://community.esri.com/t5/python-questions/stop-start-service-error/m-p/1525369#M71297</link>
      <description>&lt;P&gt;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'"&lt;/P&gt;&lt;P&gt;Portion of Script below:&lt;/P&gt;&lt;P&gt;def CreatePortalConnection():&lt;BR /&gt;try:&lt;BR /&gt;logging.info('Connecting to portal')&lt;BR /&gt;gis = GIS(PortalURL, PortalUser, PortalPass)&lt;BR /&gt;print(gis)&lt;BR /&gt;logging.info('Listing servers')&lt;BR /&gt;gis_servers = gis.admin.servers.list()&lt;BR /&gt;print(gis_servers)&lt;BR /&gt;logging.info('Specifying docking server')&lt;BR /&gt;ArcMAP = gis.admin.servers.list()[1]&lt;BR /&gt;print(ArcMAP)&lt;BR /&gt;ServerFolder = ArcMAP.services.list(Folder)&lt;BR /&gt;return ServerFolder&lt;BR /&gt;except Exception as e:&lt;BR /&gt;logging.error("Error connecting to portal: "+str(e))&lt;BR /&gt;print("Error connecting to portal: "+str(e))&lt;BR /&gt;print("QUITTING EXECUTION")&lt;BR /&gt;email(f'&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt; CONNECT TO PORTAL FAILED &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; {LogFile}', "&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt;")&lt;BR /&gt;quit()&lt;BR /&gt;&lt;BR /&gt;def stop_services(ServerFolder):&lt;BR /&gt;try:&lt;BR /&gt;if StartStop == True:&lt;BR /&gt;logging.info(f'Stopping services in {Folder} folder on ARCMAP')&lt;BR /&gt;print(f'Stopping services in {Folder} folder on ARCMAP')&lt;BR /&gt;for service in ServerFolder:&lt;BR /&gt;logging.info("Stopping - " + str(service))&lt;BR /&gt;print("Stopping - " + str(service))&lt;BR /&gt;service.stop()&lt;BR /&gt;else:&lt;BR /&gt;logging.info('Stopping services skipped by user input.')&lt;BR /&gt;print('Stopping services skipped by user input.')&lt;BR /&gt;except Exception as e:&lt;BR /&gt;logging.error("Error stopping services: "+str(e))&lt;BR /&gt;print("Error stopping services: "+str(e))&lt;BR /&gt;print("QUITTING EXECUTION")&lt;BR /&gt;email(f'&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt; STOP SERVICES FAILED &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; {LogFile}' "&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt;")&lt;BR /&gt;quit()&lt;/P&gt;&lt;P&gt;def start_services(ServerFolder):&lt;BR /&gt;try:&lt;BR /&gt;if StartStop == True:&lt;BR /&gt;logging.info(f'Starting services in {Folder} folder on ARCMAP')&lt;BR /&gt;print(f'Starting services in {Folder} folder on ARCMAP')&lt;BR /&gt;for service in ServerFolder:&lt;BR /&gt;logging.info("Starting - " + str(service))&lt;BR /&gt;print("Starting - " + str(service))&lt;BR /&gt;service.start()&lt;BR /&gt;else:&lt;BR /&gt;logging.info('Starting services skipped by user input.')&lt;BR /&gt;print('Starting services skipped by user input.')&lt;BR /&gt;except Exception as e:&lt;BR /&gt;logging.error("Error starting services: "+str(e))&lt;BR /&gt;print("Error starting services: "+str(e))&lt;BR /&gt;print("QUITTING EXECUTION")&lt;BR /&gt;email(f'&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt; START SERVICES FAILED &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; {LogFile}' "&lt;span class="lia-unicode-emoji" title=":thumbs_down:"&gt;👎&lt;/span&gt;")&lt;BR /&gt;quit()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We set the log to debug and got this additional information below (slightly redacted)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Connecting to portal: xyzx.xyzxy.xyz&lt;BR /&gt;Starting new HTTPS connection (1): xyzx.xyzxy.xyz:443&lt;BR /&gt;"GET /portal/info?f=json" 500 1208&lt;BR /&gt;"GET /portal/rest/info?f=json" 500 1208&lt;BR /&gt;"GET /portal/sharing/rest/info?f=json" 200 134&lt;BR /&gt;"GET /portal/rest/services?f=json" 500 1208&lt;BR /&gt;Generated new state DBbaHxUjLDuIdPq2DfeQF820Gaw2EG.&lt;BR /&gt;"GET /portal/sharing/rest/oauth2/authorize?response_type=token&amp;amp;client_id=pythonapi&amp;amp;redirect_uri=https%3C%2F%2Fxxxx.xyzxy.xyz&amp;amp;state=DBbaHxUjLDuIdPq2DfeQF710Gaw2EG&amp;amp;expiration=600&amp;amp;allow_verification=false&amp;amp;style=dark&amp;amp;locale=en-US" 400 854&lt;BR /&gt;Generated new state ublnZvdixx3c1rDdfhZLka5RdLQxtE.&lt;BR /&gt;"GET /portal/sharing/rest/oauth2/authorize?response_type=code&amp;amp;client_id=pythonapi&amp;amp;redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&amp;amp;state=ublnZvdixx3c1rPpfhZLka7RdLQxtE&amp;amp;expiration=20160&amp;amp;allow_verification=false&amp;amp;style=dark&amp;amp;locale=en-US" 400 854&lt;BR /&gt;Generated new state P7HGhgGIDncMUpal0FVNr1NeTb6vRM.&lt;BR /&gt;"GET /portal/sharing/rest/oauth2/authorize?response_type=token&amp;amp;client_id=arcgisonline&amp;amp;redirect_uri=https%3A%2F%2Fxxxx.xyzxy.xyz&amp;amp;state=P7HGhgGIDncMUpal0FVNr1NeTb6vRM&amp;amp;expiration=600&amp;amp;allow_verification=false&amp;amp;style=dark&amp;amp;locale=en-US" 200 1897&lt;BR /&gt;"POST /portal/sharing/oauth2/signin" 302 0&lt;BR /&gt;"POST /portal/sharing/rest/portals/self" 200 4179&lt;BR /&gt;"POST /portal/sharing/rest/community/users/portaladmin" 200 4640&lt;BR /&gt;"GET /portal/portaladmin?f=json" 302 0&lt;BR /&gt;Listing servers&lt;BR /&gt;"POST /portal/sharing/rest/portals/self/servers" 200 280&lt;BR /&gt;Starting new HTTPS connection (1): xyzx.xyzxy.xyz:6443&lt;BR /&gt;"GET /arcgis/rest/services?f=json" 200 1086&lt;BR /&gt;Incremented Retry: Retrying connection to xyzx.xyzxy.xyz timed out. (connect timeout=None)&lt;BR /&gt;"GET /arcgis/admin?f=json" 302 None&lt;BR /&gt;"GET /arcgis/admin/?f=json" 200 219&lt;BR /&gt;"GET /arcgis/admin/logs?f.json" 200 49&lt;BR /&gt;Resetting dropped connection: xyzx.xyzxy.xyz&lt;BR /&gt;"GET /mapping/rest/services?f=json" 200 320&lt;BR /&gt;Specifying docking server&lt;/P&gt;&lt;P&gt;Resetting dropped connection:&amp;nbsp;xyzx.xyzxy.xyz&lt;BR /&gt;"GET /docking/admin?f.json" 403 7070&lt;BR /&gt;ERROR - Error connecting to portal: 'Server' object has no attribute 'services'&lt;BR /&gt;EMAIL SENT&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 19:54:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-start-service-error/m-p/1525369#M71297</guid>
      <dc:creator>nacelle_pylon</dc:creator>
      <dc:date>2024-08-21T19:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Stop Start Service Error</title>
      <link>https://community.esri.com/t5/python-questions/stop-start-service-error/m-p/1526388#M71302</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/435000"&gt;@nacelle_pylon&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Here is some code I use to stop all services.&amp;nbsp; May be worth testing with this to see if you get the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 13:28:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stop-start-service-error/m-p/1526388#M71302</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-08-23T13:28:39Z</dc:date>
    </item>
  </channel>
</rss>

