Select to view content in your preferred language

ArcGIS Online User Content Issue

912
2
07-04-2013 09:58 PM
JoseSousa
Esri Contributor
Hi,

I have built automatic procedures using Python to create, delete, update, etc items on ArcGIS Online using its REST API.
Everything seems to work fine to the exception of one function.

Goal: List all the items inside of a folder in AGOL for Organizations

Because it doesn't seem to exist a method to list the items using the folders name I first need to make a request to get all the folders associated with my account/user to get their id.

That is done by invoking the URL below:
http://www.arcgis.com/sharing/rest/content/users/someuser  (the token and f=json are also added as request parameters)

Everything works fine. After discovering the ID of the folder I then issue a second request as follows:
http://www.arcgis.com/sharing/rest/content/users/someuser/some_folder_guid  (the token and f=json are also added as request parameters)

and I get the following error:
IncompleteRead(495 bytes read)

The call in Python is as follows:
urllib2.urlopen('https://www.arcgis.com/sharing/rest/content/users/' + portal_user + '/' + folder_id, urllib.urlencode(args)).read()

What actually happens is that read() function is what is taking more time. The code above is standard in python.
I have tested copying the request, args, and token into a browser and it seems to be returning the json properly.

If I catch the exception (e.g. except httplib.IncompleteRead, e 🙂 and return the e.partial info it seems to have the entire json response. The problem is that it takes almost 1 minute to read it ... and I only have 1 item inside the folder. All other methods in AGOL seem to be fast except this one which is giving an exception...

Can you guys see why only this method is not working properly?

The create webmap, delete items, etc operations seems to be working properly ...

Thanks,
Jose Sousa






If I try to list the items
Tags (2)
0 Kudos
2 Replies
TonyGegner
Regular Contributor
Hey,
Have you found any solution for this?

I have the same problem with:

    url = urljoin(AGOL, 'sharing/rest/portals/self')
    params = {'f': 'json', 'token': token}
    request = urllib2.Request(url=url, data=urllib.urlencode(params))
    r = urllib2.urlopen(request).read()

> IncompleteRead: IncompleteRead(303 bytes read)

I get the same code to work great with Portal for ArcGIS. Just doesnt work for ArcGIS Online.
0 Kudos
TonyGegner
Regular Contributor
Got a solution for you.

Request f=pjson works generally when its possible.

Otherwise you need to fix the bad requests from the server and rebuild the chunks.

You can do that by adding:
def patch_http_response_read(func):
    def inner(*args):
        try:
            return func(*args)
        except httplib.IncompleteRead, e:
            return e.partial
    return inner

httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read)
0 Kudos