0

I've got a Python script DownloadSurvey123Data.py from ArcGIS community. Trying to run this script from Windows command prompt is throwing this error after the program starts:

agol_helper = ago.AGOLHelper(portal_url)
AttributeError: 'module' object has no attribute 'AGOLHelper'"

I saw in a comment in DownloadSurvey123Data.py that ago.py is part of Python 10.3. I have Python 2.7 installed in my PC, but don't how to get Python 10.3.

Here is the complete code:

import ago
import urllib.request as urllib2
import zipfile
import json


# ID of the feature service you want to export
featureService_ID = "b5eb865444ff417ba821f5f56ade54c3"
# Output format  Shapefile | CSV | File Geodatabase
output_format = 'CSV'
# Local folder where the data will be downloaded (include slash at the end)
download_folder = "D:/Temp/"
# ArcGIS user credentials to authenicate against the portal
credentials = { 'userName' : 'xxx', 'passWord' : 'Pxxxxw0rd'}
# Address of your ArcGIS portal
portal_url = r"https://iom-dev.maps.arcgis.com/sharing"

download_file = download_folder + 'download.zip'


def downloadFile(url, filename, token):
    """
    Downloads a file from the given URL.
    :param url: URL from which to download the file
    :param filename: Name of file to store the download locally. Proper permissions are assumed.
    :param token: Token for the portal identity
    :return:
    """
    print ("...Downloading")
    req = urllib2.urlopen(url + "?token=" + token)
    CHUNK = 16 * 1024
    with open(filename, 'wb') as fp:
        while True:
            chunk = req.read(CHUNK)
            if not chunk: break
            fp.write(chunk)

def extractZIP(filename,folder):
    """
    Extracts the contents of the zip file into the specified folder.
    :param filename: The name of the ZIP archive to unpack. The file is assumed to exist.
    :param folder: The target folder to hold the content of the ZIP archive. Proper permissions are assumed.
    :return:
    """
    print ("...Extracting")
    zfile = zipfile.ZipFile(filename)
    zfile.extractall(folder)


print ("...Starting")
# initialize the portal helper class
# ago.py is part of the 10.3 python install
agol_helper = ago.AGOLHelper(portal_url)
print ("...Authenticating against your Portal ")
# login
agol_helper.login(credentials['userName'], credentials['passWord'])

# export url and parameters 
export_url = "{}/content/users/{}/export".format(agol_helper.secure_url, agol_helper.username)

export_parameters = {
    'token': agol_helper.token,
    'itemId': featureService_ID,
    'title': "Temp-" + str(int(round(time.time() * 1000))),
    'exportFormat': output_format,
    'f' :'json'
}
# launching async export request
export_data = agol_helper.url_request(export_url, export_parameters, request_type="POST")

if export_data is not None:
    print("ERROR: Can't find a feature service with id: " + featureService_ID)
    print("TIP:   Navigate to the item details page of your feature service, and get the id from the URL")
else:
    print ("...Exporting data")
    # retrieve the itemId for the export
    exportItemId = export_data['exportItemId']
    # retrieve the jobId to watch the export progress
    jobId = export_data['jobId']
    status = "processing"

    items_url = "{}/content/users/{}/items/{}/status".format(agol_helper.secure_url,agol_helper.username, exportItemId)
    data_url = "{}/content/items/{}/data".format(agol_helper.secure_url, exportItemId)

    status_parameters = {
        'jobId' : jobId,
        'jobType' : 'export',
        'f' : 'json',
        'token' : agol_helper.token
    }

    while status == "processing":
        print ("...." + status)
        # checking export job status
        time.sleep(5)
        data = agol_helper.url_request(items_url, status_parameters)

        status = data['status']

    if status == "completed":
        print ("...." + status)
        # once the export has completed, download the file
        downloadFile(data_url, download_file, agol_helper.token)
        # deleting export results in the portal
        agol_helper.delete(item_id=export_data['exportItemId'])
        # uncompress the contents of the archive
        extractZIP(download_file, download_folder)


    else:
        raise Exception("!!! Export job failed. Status \"" + status + "\"")

    print ("Completed. Files available at: " + download_folder )

The error is in line 54:

agol_helper = ago.AGOLHelper(portal_url)

Error Desc: "AttributeError: module 'ago' has no attribute 'AGOLHelper'"

Please note I have installed ArcGIS pro in my PC and am running Python script from this path:

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3>python.exe C:\Python27\DownloadSurvey123Data.py
  • 2
    Please post the entire script as text, so we can help you debug. Also there is no such thing as Python 10.3, you are probably referring to ArcMap 10.3. – RJJoling Apr 14 '18 at 10:15
  • 1
    Please always provide code snippets and full error messages (including line number) as text rather than pictures. – PolyGeo Apr 14 '18 at 10:23
  • You have this tagged with arcgis-10.0, which has been retired for many years. Please Edit the question to accurately specify the exact software in use. – Vince Apr 14 '18 at 11:55
  • i have posted completed code.i have edited my post.please check..getting error in line no 54, may be ago library not loading – user1818042 Apr 15 '18 at 8:48
  • Ago is designed for ArcMap 10.3, not ArcGIS Pro. You have tagged this question with arcgis 10.0 which refers to ArcMap, not ArcGIS Pro. Going out on a limb here and guess that module "ago" is not compatible with ArcGIS Pro: Project Status: This project is no longer being actively developed. github.com/Esri/ago-tools – RJJoling Apr 15 '18 at 8:54
1

Install ArcMap 10.3 or up and you should be able to use this module.

See Esri's Github for more information about their support for this module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.