Esri / ArcREST

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

usercontent error: #359

Open KumarSumith opened 6 years ago

KumarSumith commented 6 years ago

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 commented 6 years ago

Can you post your code so I can repo?

KumarSumith commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

**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 commented 6 years ago

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 commented 6 years ago

great, it is working. export creates an item

KumarSumith commented 6 years ago

But how can i get the data?

MikeMillerGIS commented 6 years ago

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 commented 6 years ago

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

MikeMillerGIS commented 6 years ago

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

KumarSumith commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

You mean maintaining attachments? Not sure, this is not an arcrest issue. You need to find the correct way to do this using the rest end point you are calling. Or look at another one like create replica

Sent from my Verizon 4G LTE Droid On Apr 24, 2018 4:22 AM, KumarSumith notifications@github.com wrote:

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

- You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_Esri_ArcREST_issues_359-23issuecomment-2D383846565&d=DwMFaQ&c=n6-cguzQvX_tUIrZOS_4Og&r=hoBw6CQuytVR65zzd5i-Zw&m=Im_WnZmzQlC4D4d9GBzhG0HzkqdOTuI-Y-8lq4i3Tpg&s=8CxOaC8jPwd4RhjvgCWNf0eY3Mqw_lzOdXYzdylpVK4&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AClPVXd8u9po2sCon-2DcvKMh-5FApLTVqq9ks5truCsgaJpZM4Tc8Ni&d=DwMFaQ&c=n6-cguzQvX_tUIrZOS_4Og&r=hoBw6CQuytVR65zzd5i-Zw&m=Im_WnZmzQlC4D4d9GBzhG0HzkqdOTuI-Y-8lq4i3Tpg&s=4yi3vxd93kq7SLcOJGHOGZI0vsLE3Bvv8RM-4N59NXM&e=.