# Reading values from database and converting it using python

**URL:** <https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508>\
**Category:** Maker\
**Created:** [March 16, 2021, 5:58am UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508 "2021-03-16T05:58:19Z")\
**Posts on this page:** 12\
**Page:** 3

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 28, 2023, 8:34pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/43 "2023-04-28T20:34:31Z")

</div>

Well, I should have specified that you should return it as a string, via the `html` key, but override the content type for SVG.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [April 28, 2023, 8:56pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/45 "2023-04-28T20:56:22Z")

</div>

I changed and returned it as a string via html kep did remove the error, but I was not able to show it with the image component. Can you elaborate a bit on "override the content type for the SVG"?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 28, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/46 "2023-04-28T20:58:22Z")

</div>

> **[Serve SVG with the Correct Content Type | CSS-Tricks](https://css-tricks.com/snippets/htaccess/serve-svg-correct-content-type/)**
>
> If you are trying to use SVG like or as a CSS background-image, and the file is linked to correctly and everything seems right, but the browser isn't

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [April 28, 2023, 11:16pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/47 "2023-04-28T23:16:44Z")

</div>

thank you!

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [April 29, 2023, 12:05am UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/48 "2023-04-29T00:05:02Z")

</div>

Actually there is still a problem with the Webdev approach.  
The left one is generated with the Webdev, and it just displays dark grey color(`	return {'html': svg_string,'contentType': 'image/svg+xml'}`). The Right one is generated with the old approach with script, showing the correct heat map. Is there something else I need to do?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/e/7ecdf9dba48357adf2702aa651bc7e63e9016c5f.jpeg)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 29, 2023, 12:33am UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/49 "2023-04-29T00:33:05Z")

</div>

Can you use your browser's dev tools to see if the content type came through correctly?

You may need to encode the string to bytes after all, if the `html` key won't let you override the content type.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [April 29, 2023, 2:46am UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/50 "2023-04-29T02:46:07Z")

</div>

not sure what happened, but it is magically working now. Thanks @pturmel for your time!

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/e/feaec870da5ae25ffbdb3a0828b8cb29e5818604.jpeg)

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [May 1, 2023, 1:09pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/51 "2023-05-01T13:09:07Z")

</div>

I just have a follow-up question regarding the WebDev module. When I am using the Webdev module to query the data and generate the SVG, does that mean I am utilizing the web browser to perform the computing instead of the Ignition Gateway?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 1, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/52 "2023-05-01T13:19:14Z")

</div>

No, the WebDev code runs entirely on the gateway.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [May 1, 2023, 1:32pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/54 "2023-05-01T13:32:22Z")

</div>

Okay, what I don't understand is what aspect we are improving by using the Webdev module compared to assigning the base64 data URL to the image component?

Also, when using the Webdev module to generate the SVG, I did not see any spike in the Gateway memory, but the web browser did consume a lot of memory on my computer when loading the image in the web browser. Is there an explanation for it?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 1, 2023, 1:38pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/55 "2023-05-01T13:38:36Z")

</div>

> [@jfan](#):
>
> what aspect we are improving

You are moving a "heavy" display item from being computed inline with the image component to out-of-line as the image component's source. This is particularly important when the image component is nested in a table. You also avoid a slight computational penalty of encoding to base64 on the gateway and decoding the base64 in the browser.

Using separate URLs per image also allows the browser to cache them, and you can have your WebDev code cache the SVGs on that end, too. When inline, no caching is possible.

I have no idea why your browser's memory consumption spikes.

---

<div class="post-metadata">

**Author:** ![jfan](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jfan](https://forum.inductiveautomation.com/u/jfan)\
**Post date:** [May 1, 2023, 1:45pm UTC](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508/56 "2023-05-01T13:45:31Z")

</div>

Thank you so much! and that makes sense.

[Previous page](https://forum.inductiveautomation.com/t/reading-values-from-database-and-converting-it-using-python/44508.md?page=2)
