akaralokian_RWH2O

Issue Accessing WorkForce via Python Script

Discussion created by akaralokian_RWH2O on Dec 12, 2019

Hello,

 

I have been working on a standalone Python script that queries a feature class of fire hydrants in ArcGIS Pro and automatically assigns tasks for their inspection to a list of available workers. I would like to connect this program to WorkForce to download a list of workers associated with the project and then upload assignments back to WorkForce after the script delegates hydrants to workers.

 

I have been encountering issues with having the script interface with WorkForce, and I cannot seem to access the existing WorkForce project from the script. I have been using the arcgis.gis.GIS command to attempt to log in to the account. The code I have written so far looks like this, and seems to match the format given in the second sample of the help file loaded with the GIS command:

 

import arcgis

from arcgis.gis import GIS 

 

# Code not involved with connecting to WorkForce

 

GISName = GIS(username = "TheAccountUsername", password = "TheAccountPassword")

Item = GISName.content.get(<the item ID of the project>)

Project = arcgis.apps.workforce.Project(Item)
Workers = project.workers.search()

 

I have attempted listing the URL argument of the GIS command as the URL of the login screen of WorkForce, and I have also tried entering the 'None' Python null value as the URL argument, which the help file indicates will redirect it to the ArcGIS Online login screen, from which it may still be possible to access WorkForce. I have also attempted placing carets around the username and password, which I have seen in some previous solutions that have worked for others.

 

When the code is run, the program stops on the line where GISName is defined with RuntimeError: Unable to Generate Token, Invalid Username or Password, (Error Code: 400). 

 

I have tried going to the ArcGIS Online login page and manually entering the same credentials, which logs me in successfully.

 

Additionally, the import commands for the ArcGIS library only work when pasted or typed into the Python window of ArcGIS Pro. When the program is run from the shell, the shell can't seem to find the library and gives a name error for the name of the library. For this reason, I have been testing the code by copying and pasting it, in full, into the Python window of ArcGIS Pro. I would like to eventually be able to run this script from the Python shell, if it is possible to do so.

 

Any and all help with these issues is greatly appreciated.

Outcomes