# 500 errors from Webdev

**URL:** <https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269>\
**Category:** Ignition\
**Created:** [June 1, 2022, 4:00pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269 "2022-06-01T16:00:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 4:00pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/1 "2022-06-01T16:00:29Z")

</div>

Is there any other examples of using the servletRequest parameter in the Web Dev http methods? I am having the same issue with the 500 server error returning no matter if I return one of the required keys or return None.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 4:14pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/2 "2022-06-01T16:14:35Z")

</div>

That’s really not enough information to diagnose what’s happening. Start with checking your gateway’s logs to see what the actual 500 error is.

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 4:28pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/3 "2022-06-01T16:28:01Z")

</div>

It’s a Traceback error executing on a line in my code where I am using a system.db.runQuery such as this:

testAnswer = system.db.runQuery(“INSERT INTO public.vin\_posts(vin\_data, dict\_data) VALUES(’{}’, ‘{}’)”.format(data, moreData), “eol\_post\_test”)

It posts in my database just fine but I still get the error in the logs and Postman.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 4:32pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/4 "2022-06-01T16:32:28Z")

</div>

You should be using `runPrepQuery` for safe value substitution, but that’s a diversion.

_What is the actual error being logged_?  
There will be a clear “this is what went wrong” exception being thrown, somewhere in the error. Post the full exception here, in a preformatted text block, and I can help you. Without that, I’m flying blind.

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 4:53pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/5 "2022-06-01T16:53:21Z")

</div>

```auto
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 6, in doPost at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362) at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runQuery(AbstractDBUtilities.java:333) at jdk.internal.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.Exception: java.lang.Exception: Error executing system.db.runQuery(INSERT INTO public.vin_posts(vin_data, dict_data) VALUES('5a2b173379', '{"lastName":"Blow","firstName":"5a2b173379","password":"abc123!@","role":"student","email":"under@gmail.com"}'), eol_post_test, )

at org.python.core.Py.JavaError(Py.java:547)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:362)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runQuery(AbstractDBUtilities.java:333)

at jdk.internal.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:190)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:541)

at org.python.core.PyObject. __call__ (PyObject.java:477)

at org.python.core.PyObject. __call__ (PyObject.java:481)

at org.python.pycode._pyx28.doPost$1(:17)

at org.python.pycode._pyx28.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:306)

at org.python.core.PyFunction.function ___call__ (PyFunction.java:474)

at org.python.core.PyFunction. __call__ (PyFunction.java:469)

at org.python.core.PyFunction. __call__ (PyFunction.java:464)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:831)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:813)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:806)

at com.inductiveautomation.webdev.gateway.handlers.PythonResourceHandler.doRequest(PythonResourceHandler.java:294)

at com.inductiveautomation.webdev.gateway.handlers.PythonResourceHandler.doPost(PythonResourceHandler.java:547)

at com.inductiveautomation.webdev.gateway.servlets.WebDevDispatch.doPost(WebDevDispatch.java:153)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

at com.inductiveautomation.webdev.gateway.servlets.WebDevDispatch.service(WebDevDispatch.java:118)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)

at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1450)

at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799)

at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1626)

at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:548)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)

at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)

at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)

at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)

at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)

at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)

at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)

at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)

at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349)

at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at com.inductiveautomation.catapult.handlers.RemoteHostNameLookupHandler.handle(RemoteHostNameLookupHandler.java:121)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)

at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59)

at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)

at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)

at org.eclipse.jetty.server.Server.handle(Server.java:516)

at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388)

at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633)

at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)

at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277)

at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)

at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)

at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173)

at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)

at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:386)

at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883)

at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: java.lang.Exception: java.lang.Exception: Error executing system.db.runQuery(INSERT INTO public.vin_posts(vin_data, dict_data) VALUES('5a2b173379', '{"lastName":"Blow","firstName":"5a2b173379","password":"abc123!@","role":"student","email":"under@gmail.com"}'), eol_post_test, )

... 67 common frames omitted

Caused by: java.lang.Exception: Error executing system.db.runQuery(INSERT INTO public.vin_posts(vin_data, dict_data) VALUES('5a2b173379', '{"lastName":"Blow","firstName":"5a2b173379","password":"abc123!@","role":"student","email":"under@gmail.com"}'), eol_post_test, )

... 66 common frames omitted

Caused by: org.postgresql.util.PSQLException: No results were returned by the query.

at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:225)

at org.apache.commons.dbcp2.DelegatingStatement.executeQuery(DelegatingStatement.java:329)

at org.apache.commons.dbcp2.DelegatingStatement.executeQuery(DelegatingStatement.java:329)

at com.inductiveautomation.ignition.gateway.datasource.DelegatingStatement.executeQuery(DelegatingStatement.java:64)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRStatement.executeQuery(SRConnectionWrapper.java:793)

at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper.runQuery(SRConnectionWrapper.java:191)

at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities._runQuery(GatewayDBUtilities.java:215)

at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runQuery(AbstractDBUtilities.java:329)

... 64 common frames omitted

```

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 5:03pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/6 "2022-06-01T17:03:09Z")

</div>

```auto
        jsonEntry = request['data']
	if(len(jsonEntry) != 0):
		data = str(jsonEntry['firstName'])
		moreData = system.util.jsonEncode(jsonEntry)
		testAnswer = system.db.runQuery("INSERT INTO public.vin_posts(vin_data, dict_data) VALUES('{}', '{}')".format(data, moreData), "eol_post_test")
		#testAnswer = system.db.runPrepUpdate("INSERT INTO public.vin_posts (vin_data, dict_data) VALUES (?,?)", [data, moreData], "eol_post_test")
	else:
		testTwo = request['servletRequest'].inputStream()
		print(testTwo)
		e = system.utils.jsonEncode(testTwo)
		return {'json': e}
		
#	test = request['servletResponse'].outputStream()
#	print(test)
#	s = system.utils.jsonEncode(test)
	return {'json': jsonEntry} 

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 5:19pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/7 "2022-06-01T17:19:34Z")

</div>

```nohighlight
Caused by: org.postgresql.util.PSQLException: No results were returned by the query.

```

You’re running an UPDATE query via `runQuery`. JDBC (and thus the Postgres JDBC driver, which is what is ultimately throwing this exception) differentiate between queries and updates programmatically.

You’ve got this line commented out:

```auto
#testAnswer = system.db.runPrepUpdate("INSERT INTO public.vin_posts (vin_data, dict_data) VALUES (?,?)", [data, moreData], "eol_post_test")

```

That’s the right way to issue this. Was that giving you some issue? Running an update won’t give you a _response_ beyond the number of affected rows, but there’s no more information to get from an INSERT statement.

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/8 "2022-06-01T17:28:08Z")

</div>

I commented out the runPrepUpdate() because it wasn’t posting in the db for me. The runQuery() is the only one I can get to work for some reason.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 5:36pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/9 "2022-06-01T17:36:12Z")

</div>

Hm, `runPrepUpdate` is _definitely_ the right way to do this.

`testAnswer` will be an integer on response. I’m not sure what output you’re looking for from the HTTP body. If you want to return the user details, perhaps issue a second query for the newly created user? Something like:

```python
insertPost = "INSERT INTO public.vin_posts (vin_data, dict_data) VALUES (?,?)"
key = system.db.runPrepUpdate(insertPost, [data, moreData], "eol_post_test", getKey=True)
queryPost = "SELECT * FROM public.vin_posts WHERE id=?"
createdRow = system.db.runPrepQuery(queryPost, [key], "eol_post_test")

```

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 8:17pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/10 "2022-06-01T20:17:30Z")

</div>

Been trying different variations but runPrepQuery or runPrepUpdate doesn’t post at all in the db. The only progress I am getting is with the runQuery.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 1, 2022, 8:22pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/11 "2022-06-01T20:22:54Z")

</div>

I can’t really fathom why that would be. If there’s e.g. a key constraint, then I would expect an error to be thrown. If you’re missing required info, an error should be thrown. There’s not very many ways for an INSERT to silently fail; it pretty much either works or it doesn’t. If you drop the `getKey` param and just log the return value, is the driver telling you you’ve updated one row in the DB? If you put the `gateway.database.updates` logger on TRACE you can see the actual query Ignition is executing, and you should also be able to see the incoming query in Postgres, somehow.

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 8:36pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/12 "2022-06-01T20:36:40Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/de661996e7b81e30d2887362f0c9739c2cd4eaec.png)

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 1, 2022, 8:40pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/13 "2022-06-01T20:40:43Z")

</div>

In the logs I do notice these false values in the queries. Does that have something to do with it?

---

<div class="post-metadata">

**Author:** ![Richard\_Dixon](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@Richard\_Dixon](https://forum.inductiveautomation.com/u/Richard_Dixon)\
**Post date:** [June 2, 2022, 1:24pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/14 "2022-06-02T13:24:01Z")

</div>

Good morning.  
I know I should be using the runPrep but since I feel pressured by time I will come back to that later. I am thinking this is a reason I am running into this 500 error and how can I use the servletResponse to send a proper status code to client?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/5/e5e9f09277e27b34c9dc9e7ba4427dbd96d73a99.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 2, 2022, 2:25pm UTC](https://forum.inductiveautomation.com/t/500-errors-from-webdev/60269/15 "2022-06-02T14:25:55Z")

</div>

The 500 error is being returned because the Python handler is throwing an exception. If you wrap your code that’s throwing in a try/catch (you may need to separately catch `java.lang.Exception`, for Jython compatibility reasons) then your endpoint should stop returning 500. You _can_ use `servletResponse` to set a specific response code, but it’s not generally required if a default 200 is fine.  
It would look something like this:  
`request['servletResponse'].status = 200`  
However, it’s probably not working because the exception thrown is engaging our handling, which will override any status you attempt to set. Which loops back to requiring you to catch the exception.
