Hi there,
I am attempting to write a script using the Python API that reports on user activity (inspired by https://developers.arcgis.com/python/samples/inventory-organizational-content/) and data usage.
I work for a large organization with almost 17,000 users, and I'm finding that, while looping through all of these users to examine the content they've created (basically using the same code as in the 'Compiling Organization Content' section of the document linked above), Python will start throwing the "'Response' object is not subscriptable" error once the loop reaches the 3,884th record.
Here's the code I'm using:
gis = GIS('connection info in here')
seconds_in_one_year = 31536000
never_logged_in = []
one_year_idle = []
org_content = []
count = 0
print('Checking last login times...')
for u in users:
print('({}/{}) - {}'.format(count, len(users), u.username))
last_login = u.lastLogin / 1000
# If they've never logged in
if last_login < 1:
never_logged_in.append(u.username)
# If their last log in was over one year ago
if last_login < time.time() - seconds_in_one_year:
one_year_idle.append(u.username)
# Examine items
try:
user_content = gis.content.advanced_search(query='owner: ' + u.username, max_items=-1)['results']
org_content += user_content
except Exception as e:
print('{} - Error: {}'.format(u.username, e))
count += 1
print('Found {} users who have never logged in and {} who have been one year idle.'.format(len(never_logged_in), len(one_year_idle)))
Except from the output of this script:
...
(3876/16997) - farhata2
(3877/16997) - fariaca2
(3878/16997) - farleym3
(3879/16997) - farmerb1
(3880/16997) - farmerju
(3881/16997) - faroo125
(3882/16997) - faroo127
(3883/16997) - faroo165
faroo165 - Error: A general error occurred: 'Response' object is not subscriptable
(3884/16997) - faroo175
faroo175 - Error: A general error occurred: 'Response' object is not subscriptable
(3885/16997) - faroo197
faroo197 - Error: A general error occurred: 'Response' object is not subscriptable
(3886/16997) - faroo204
faroo204 - Error: A general error occurred: 'Response' object is not subscriptable
(3887/16997) - farooqas
farooqas - Error: A general error occurred: 'Response' object is not subscriptable
(3888/16997) - farooqmi
farooqmi - Error: A general error occurred: 'Response' object is not subscriptable
...
Does anyone have any thoughts on why this might be occurring or ideas for potential solutions/workarounds?
Thank you,
Cole