Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

url properties aren't encoded before calling #177

Closed DShokes closed 8 years ago

DShokes commented 8 years ago

The outputs to some analysis tools are not replacing " " with "_" automatically for map viewer users. As a result, we have some feature services with names like "http://services.arcgis.com//arcgis/rest/services/2015 Field Day Drive Time/FeatureServer".

This causes running the sample addFieldToHostedFeatureService.py on a different service to fail because of the for-loop. featureservice.layers raises HTTP Error 400: Bad Request. the featureservice url attribute can't be set so I'm not sure of a workaround.

DShokes commented 8 years ago

I made a work around that encodes spaces in service names and removes 'admin/' from the url string. This gives me all of the feature services in non-admin form

agolServices = arcrest.hostedservice.Services(url1, securityHandler=securityHandler) # from sample
def getservices(agolservices):
    fixed_admin_urls = [x.url.replace('admin/','').replace(' ', '%20') for x in agolServices.services if hasattr(x,'url') and x.url] # fast
    services = [arcrest.agol.FeatureService(y, securityHandler) for y in fixed_admin_urls] # fine
    return services
def servicesandlayers(agolservices):
    services = getservices(agolservices)
    return [sldict(s) for s in services]
def sldict(s):
    return {s:s._layers}

With these functions I can then query every feature in the organization! Ultimately, this allows me to build auditing tables on a local sql server to track feature edits. In a disaster recovery scenario, such as when features are incorrectly deleted online, I have backup options at the individual feature level.

The url encoding should still probably be fixed so no other users run into this issue.

achapkowski commented 8 years ago

I added code to encode the values in each get/post.