Python code question

1750
12
07-14-2017 10:17 AM
LeifJohnson
New Contributor II

Hello, i downloaded a python code that is intended to send email notification to me when a feature has been added to a layer. I'm a novice when it comes to codes and coding and keep getting stuck. To clarify a little further i saw a document (link here) that i am attempting to implement. I downloaded the code and tried for awhile trying to get it to work but unfortunately i haven't had any luck. The error i keep receiving is "Cannot perform query. Invalid query parameters.
Unable to perform query. Please check your parameters.
No where clause specified.
(Error Code: 400)" ....I think it has something with the way i am querying the information but not sure. I marked out all of the username and passwords but if anyone had any suggestions on how i might get the enclosed file to start working it would be greatly appreciated. 

To add on i'm using python 3.5.3

0 Kudos
12 Replies
RandyBurton
MVP Alum

Around line 64, instead of:

'query': "'STATUS'= 'Unassigned'",

Try it without single quotes around STATUS:

'query': "STATUS = 'Unassigned'",
0 Kudos
LeifJohnson
New Contributor II

Thanks Randy for your reply. I tried doing that and get the same message. 

0 Kudos
RandyBurton
MVP Alum

I noticed a slash at the end of your service url around line 62. I don't think it should be there, so try removing it along with my previous suggestion.

'service url': 'https://services6.arcgis.com/ ... /Complaint/FeatureServer/0/'

If that doesn't fix it , then I'd add a "print sql" around line 115, as indicated above, which should show you what the where query is.

# build sql
sql = "{} != '{}'".format(message['status field'], message['completed value'])
sql += " AND {}".format(message['query'])

print sql # find out if sql is being properly formated

feature_layer = FeatureLayer(email_service['service url'], target)
features = _get_features(feature_layer, sql)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

  From the code it looks like it should be:

EMAIL != 'Completed' AND STATUS = 'Unassigned'   

Are the fields STATUS and EMAIL in the feature you are querying?

Also, does the error message indicate which line it is happening on? It looks like the JSON response from the query is being printed out.

LeifJohnson
New Contributor II

Thanks Randy...I'll give it a try on Monday when i'm back in the office. I appreciate your help on this. 

0 Kudos
LeifJohnson
New Contributor II

Thank again Randy...I tried your suggestions and seemed to generate the same error. I'm thinking maybe i don't have my python IDE properly set to Python 3.5.3. Do you have any suggestions on the best way to go about checking this?

0 Kudos
LukeWebb
Occasional Contributor III

We need to know exactly what was printed as your attempted SQL where clause,  as Randy indicated:

Quote:

If that doesn't fix it , then I'd add a "print sql" around line 115, as indicated above, which should show you what the where query is.

Please add a line:

print sql

as line 115 and tell us the result.

Also, we need to know the line of the script that crashes, this should be printed in the error: 

Also, does the error message indicate which line it is happening on? It looks like the JSON response from the query is being printed out.

LeifJohnson
New Contributor II

Luke, the print i receive is : 

EMAIL != 'Completed' AND STATUS = 'Unassigned'
Cannot perform query. Invalid query parameters.
'where' parameter is invalid
Cannot perform query. Invalid query parameters.
'where' parameter is invalid
(Error Code: 400) 

Thanks in advance for your help

0 Kudos
RandyBurton
MVP Alum

Around line 115, change the query to:

# build sql
sql = "{} <> '{}'".format(message['status field'], message['completed value'])
sql += " AND {}".format(message['query'])

I believe the SQL for AGOL uses "<>" instead of "!=" for not equals.  Also, no single quotes around the field names.

JonathanQuinn
Esri Notable Contributor

Woops, didn't see this reply.

0 Kudos