Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

usercontent error: #359

Open
KumarSumith opened this issue Apr 20, 2018 · 14 comments
Open

usercontent error: #359

KumarSumith opened this issue Apr 20, 2018 · 14 comments

Comments

@KumarSumith
Copy link

KumarSumith commented Apr 20, 2018

I am trying to run the code to export the data from arcgis to my local PC using arcrest library but i get this error. Thanks

AttributeError: 'Content' object has no attribute 'usercontent'

ArcRest or ArcRestHelper

Version or date of download

Bug or Enhancement

Repo Steps or Enhancement details

@MikeMillerGIS
Copy link
Member

Can you post your code so I can repo?

@KumarSumith
Copy link
Author

I have added the codes. I found this code online.

I have also tried the code available in this link (https://github.com/Esri/ArcREST). But I can only get the meta-data.

Thank you

import uuid
import os
import time

Inputs

itemID = ""
username = ""
pw = ""
url = ""
filePath = r""

Logic

Create security handler

shAGOL = arcrest.AGOLTokenSecurityHandler(username, pw)

Connect to AGOL

org = arcrest.manageorg.Administration(url=url, securityHandler=shAGOL)

Grab the user's content (items)

content = org.content
usercontent = content.usercontent()

Create a export item with a random name using UUID

and export it to a zipfile

result = usercontent.exportItem(title="%s" % uuid.uuid4().get_hex(),
itemId=itemID,
exportFormat=exportDataAs,
exportParameters=None)

exportedItemId = result['exportItemId']
jobId = result['jobId']
exportItem = content.item(itemId=exportedItemId)

Ensure the item is finished exporting before downloading

status = usercontent.status(itemId=exportedItemId, jobId=jobId, jobType="export")

while status['status'].lower() == "processing":
time.sleep(3)
status = usercontent.status(itemId=exportedItemId,
jobId=jobId,
jobType="export")
filePath = exportItem.itemData(f="json", savePath=filePath)

Erase the exported item to clean up

AGOL

usercontent.deleteItems(items=exportItem.id)
del exportItem
print ('finishe!')

@MikeMillerGIS
Copy link
Member

try this:

                                                                                ```

import uuid                                                                     
import os                                                                       
import time                                                                     
import arcrest                                                                  
import arcresthelper                                                            
itemID = ""                                                                     
username = ""                                                                   
pw = ""                                                                         
url = ""                                                                        
filePath = r""                                                                  
exportDataAs = "CSV"                                                            
#   Logic                                                                       
#                                                                               
#  Create security handler                                                      
shAGOL = arcrest.AGOLTokenSecurityHandler(username, pw)                         
#  Connect to AGOL                                                              
admin = arcrest.manageorg.Administration(url=url, securityHandler=shAGOL)       
content = admin.content                                                         
user = content.users.user()                                                     
result =  user.exportItem(title="%s" % uuid.uuid4().get_hex(),                  
                                     itemId=itemID,                             
                                     exportFormat=exportDataAs,                 
                                     exportParameters=None)                     

@KumarSumith
Copy link
Author

**Hi Mike,
Thank you very much for your help. I have few questions regarding the above code:

Everytime i run the line "shAGOL = arcrest.AGOLTokenSecurityHandler(username, pw)" I get the following. Is it normal?**

notificationsEnabled - attribute not implemented in Portal class.
allowedExternalLinks - attribute not implemented in Portal class.
vectorBasemapGalleryGroupQuery - attribute not implemented in Portal class.
canSetCustomBuyLink - attribute not implemented in Portal class.
eueiEnabled - attribute not implemented in Portal class.
canSetQuestionnaire - attribute not implemented in Portal class.
useVectorBasemaps - attribute not implemented in Portal class.
allowedOrigins - attribute not implemented in Portal class.
defaultVectorBasemap - attribute not implemented in Portal class.
contentCategorySetsGroupQuery - attribute not implemented in Portal class.
isVerified - attribute not implemented in Portal class.
allowedRedirectUris - attribute not implemented in Portal class.
notificationsEnabled - attribute not implemented in Portal class.
allowedExternalLinks - attribute not implemented in Portal class.
vectorBasemapGalleryGroupQuery - attribute not implemented in Portal class.
canSetCustomBuyLink - attribute not implemented in Portal class.
eueiEnabled - attribute not implemented in Portal class.
canSetQuestionnaire - attribute not implemented in Portal class.
useVectorBasemaps - attribute not implemented in Portal class.
allowedOrigins - attribute not implemented in Portal class.
defaultVectorBasemap - attribute not implemented in Portal class.
contentCategorySetsGroupQuery - attribute not implemented in Portal class.
isVerified - attribute not implemented in Portal class.
allowedRedirectUris - attribute not implemented in Portal class.

Also I am still getting the error for "user=content.users.user(). The error message is below:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Sumith Kumar\Anaconda2\lib\site-packages\arcrest\manageorg_content.py", line 197, in user
initalize=True)
File "C:\Users\Sumith Kumar\Anaconda2\lib\site-packages\arcrest\manageorg_content.py", line 1975, in init
self.__init()
File "C:\Users\Sumith Kumar\Anaconda2\lib\site-packages\arcrest\manageorg_content.py", line 1999, in __init
if self._location.find(res['username'].lower()) > -1:
TypeError: string indices must be integers, not str

**Is there any library I am missing? Please help as I am stuck with this problem for long time.

Thank you for your time.**

@KumarSumith
Copy link
Author

Update:

i added ssl and managed to pass that stage.
But when i run the last line of code that you have given i get nothing. I printed the result to show what is in the variable but i get this:

result = user.exportItem(title="%s" % uuid.uuid4().get_hex(),itemId=itemID,exportFormat=exportDataAs,exportParameters=None)

result
<arcrest.manageorg._content.UserItem object at 0x000000000C7600B8>
for a in result:
... print a
...
groupDesignations - attribute not implemented in UserItem class.
scoreCompleteness - attribute not implemented in UserItem class.
[u'item', {u'itemType': u'file', u'proxyFilter': None, u'culture': u'english (united states)', u'owner': u'atadmin', u'guid': None, u'screenshots': [], u'id': u'923e54f7ca654e77be1388d17e60b0b5', u'size': 3670, u'appCategories': [], u'access': u'private', u'avgRating': 0, u'title': u'37dcd34138b14ac0b6a37cc881eb7017', u'groupDesignations': None, u'numRatings': 0, u'numComments': 0, u'snippet': None, u'listed': False, u'largeThumbnail': None, u'itemControl': u'admin', u'type': u'CSV Collection', u'thumbnail': None, u'uploaded': 1524500834000L, u'industries': [], u'numViews': 0, u'description': None, u'tags': [u'export'], u'typeKeywords': [u'CSV Collection'], u'extent': [[-180, -90], [180, 90]], u'scoreCompleteness': 16, u'banner': None, u'properties': None, u'categories': [], u'name': u'37dcd34138b14ac0b6a37cc881eb7017', u'licenseInfo': None, u'languages': [], u'url': None, u'lastModified': -1, u'documentation': None, u'modified': 1524500844000L, u'spatialReference': None, u'item': u'37dcd34138b14ac0b6a37cc881eb7017.zip', u'protected': False, u'ownerFolder': None, u'accessInformation': None}]
[u'sharing', {u'access': u'private', u'groups': []}]

@MikeMillerGIS
Copy link
Member

great, it is working. export creates an item

@KumarSumith
Copy link
Author

But how can i get the data?

@MikeMillerGIS
Copy link
Member

you should be able to download it from the resulting item/

If you want to get the data without creating an item, you could look at the createReplica sample

@KumarSumith
Copy link
Author

Can i have a sample to download from the resulting item please..

@MikeMillerGIS
Copy link
Member

try this one?
https://github.com/Esri/ArcREST/blob/master/samples/create_replica_portal_item.py

@KumarSumith
Copy link
Author

Hi Mike,
I took the export part from create_replica_portal_item.py and added in the existing code. Finally it works. The code generated the zip file that contains 2 files (metadata.csv and surveydata.csv).
Thank you very much for your time and help. I will upload the entire code so that others can also use it.
Once again that you very much Mike. You are the true savior.

@MikeMillerGIS
Copy link
Member

no problem. If you can, I would suggest moving your processes to the Python API for ArcGIS. ArcRest still has its value if you are stuck with python 2.x.

@KumarSumith
Copy link
Author

Hi Mike, The data in ArcGIS online has some images that does not appear in the csv file. I changed "exportDataAs = "CSV"" to "exportDataAs = "File Geodatabase"" and got the zip folder with goedatabase files. Is there a way I can save the data into MSSQL along with the image.
Thank you

@MikeMillerGIS
Copy link
Member

MikeMillerGIS commented Apr 24, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants