{"error":"Error: Access not allowed request\n(Error Code: 403)"}
There's a few problems going on. The url param when initializing the GIS should be the url to your portal. Additionally, your feature_service_url is not pointing to a Feature Service, but a Feature Service Layer. You should remove "/2"
In my enterprise portal, there is a geodatabase file that I would like to access. From there, I would like to get the domain information. Could you please help me with this?
I try to break things up into smaller try:except: blocks so that the place the error happens is more apparent.
portal = "https://cyinprha.corp.cyient.com/portal/"
try:
gis = GIS(url=portal, username=username, password=password)
print("Logged in")
except Exception as e:
print(e)
return
I show connecting to Portal because I can't use "server" here. I assume that you don't have a federated portal, I've never worked in that environment.
I've never tried to use a hosted file gdb. Now I have to go try that!
Jupyter notebooks are a good way to test this stuff too. Especially from VS Code
Yeah the docs say url "should be a web address to either an ArcGIS Enterprise portal or to ArcGIS Online in the form: <scheme>://<fully_qualified_domain_name>/<web_adaptor>"
I am able to connect to my portal for arcgis but unable to access the feature service which is published as a gdb file
Okay, well, I followed the instructions I found here: https://enterprise.arcgis.com/en/portal/latest/use/publish-features.htm#ESRI_SECTION1_F878B830119B44...
I put a feature class into an FGDB and then zipped it, then in Portal I published it as a feature service. My URL is similar to yours so I am assuming you did something similar. It's like publishing a shapefile.
My feature service is https://delta.co.clatsop.or.us/server/rest/services/Hosted/comm_gdb/FeatureServer
Now I have a way to try out your code.
Geez the docs are so hard to use now, but all nicely formatted in Esri web site! Sad. "Not invented here" syndrome. Anyway.
The contentmanager (https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#contentmanager) "get"method only accepts an item id from Portal and you are feeding it a URL. Find the item id and feed it that instead.
import pprint
# assuming you did the login thing here and have an object "gis"...
item = gis.content.search(service_url)[0]
pprint.pprint(item)
Not sure what you want to do from here. For my feature services I get this:
<Item title:"comm_gdb" type:Feature Layer Collection owner:bwilson@CLATSOP>
I try to answer questions here because I learn a LOT every time I do. This time around I learned how to publish a FGDB. I probably never will 🙂 but it's good to know how it works.
I never tried to do a "search" on a complete URL so it was interesting to see that it worked at all. Normally I search on a title or some short string. There are many options for the search method, arguably too many. 🙂
I don't see a quick way to get the itemId from the "item" object so that you can do the "get" call, and you can't feed the "item" into it.
I dug around in my own code and found how I do it. I bypass the Python API and use a _con. Looks like this
class PortalContent(object):
def __init__(self, gis):
self.gis = gis
return
def findItems(self, title=None, name=None, type=None) -> list:
"""
Search the Portal using any combination of name, title, and type.
Return the list of items, which might be empty.
"""
connection = gis._con
# https://developers.arcgis.com/rest/users-groups-and-items/search-reference.htm
url = connection.baseurl + 'search'
q = ''
if name:
q += 'name:"%s"' % name
if title:
if q: q += ' AND '
q += 'title:"%s"' % title
if type:
if q: q += ' AND '
q += 'type:"%s"' % type
params = {
'q': '', # This is required. This is the fuzzy match operation.
'filter': q # This is the exact match operation.
}
res = connection.post(url, params)
return res['results']
def findIds(self, title=None, name=None, type=None) -> list:
"""
Search the Portal using any combination of name, title, and type.
Return a list of ids, which might be empty.
"""
items = self.findItems(title, name, type)
ids = [item['id'] for item in items]
return ids