HOW TO
A server certificate is a digital file containing information about the identity of the web server and is used to authenticate the server's identity to the client. Instead of importing server certificates through the REST endpoints of the Portal Administrator Directory and the ArcGIS Server Administrator Directory, the Python scripts provided in this article can also be used to import existing certificates to Portal for ArcGIS and ArcGIS Server.
Depending on the product, use one of the Python scripts below to import existing server certificates.
import arcgis
gis = arcgis.GIS("https://hostname.domain.com/portal","<username>","<password>") ssl = gis.admin.security.ssl
ssl.import_server_certificate("<certificateAlias>", "<privatekey>", r"<filepath>.pfx") ssl.update("<certificateAlias>", ssl.properties["<sslProtocols>"], ssl.properties["<cipherSuites>"])
The Python script below is the full sample script to import an existing server certificate to Portal for ArcGIS and update the web server certificate alias.
import arcgis gis = arcgis.GIS("https://testserver.esri.com/portal","adminuser","adminpassword") ssl = gis.admin.security.ssl ssl.import_server_certificate("TestCert", "cer46s5ae1fr98r", r"C:\Users\USER\Desktop\Cert\Cert.pfx") ssl.update("TestCert", ssl.properties["TLSv1.2"], ssl.properties["TLS_RSA_WITH_AES_128_CBC_SHA"])
from arcgis.gis import GIS from arcgis.gis.server import Server
gis = GIS(url="https://hostname.domain.com/portal", username="<username>", password="<password>") urlHosting = "https://hostaname.domain.com/server" hostingServer = Server(url=urlHosting, gis=gis)
cert= r"<filepath>.pfx"
for machine in hostingServer.machines.list(): machine.import_existing_server_certificate("<cerificateAlias>","<privatekey>", cert)
The Python script below is the full sample script to import an existing server certificate to ArcGIS Server. Unlike Portal for ArcGIS, there is no documented way to update the ArcGIS Server web server certificate alias using ArcGIS API for Python.
from arcgis.gis import GIS from arcgis.gis.server import Server gis = GIS(url="https://testserver.esri.com/portal", username="adminuser", password="adminpassword") urlHosting = "https://testserver.esri.com/server" hostingServer = Server(url=urlHosting, gis=gis) cert= r"C:\Users\USER\Desktop\Cert\Cert.pfx" for machine in hostingServer.machines.list(): machine.import_existing_server_certificate("TestCert","cer46s5ae1fr98r", cert)
Get help from ArcGIS experts
Download the Esri Support App