skip to Main Content

I am using the json2html package to convert JSON to HTML but I am getting the error – "fork/exec /home/sftp_user/uploads/json2html.py: exec format error"

Here is what I have done

Script is as below

#!/usr/bin/env python3
import sys
from json2html import *
from json import loads

ip = json.loads(sys.argv[1])
res = json2html.convert(json={"data":ip})
sys.stdout.write(res)

The sys.argv[1] payload is below

[ { "FirstName": "John", "LastName": "Doe", "StreetName": "120 jefferson st.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Jack", "LastName": "McGinnis", "StreetName": "220 hobo Av.", "County": "Phila", "State": " PA", "PostCode": 9119 }, { "FirstName": "John "Da Man"", "LastName": "Repici", "StreetName": "120 Jefferson St.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Stephen", "LastName": "Tyler", "StreetName": "7452 Terrace "At the Plaza" road", "County": "SomeTown", "State": "SD", "PostCode": 91234 }, { "FirstName": null, "LastName": "Blankman", "StreetName": null, "County": "SomeTown", "State": " SD", "PostCode": 298 }, { "FirstName": "Joan "the bone", Anne", "LastName": "Jet", "StreetName": "9th, at Terrace plc", "County": "Desert City", "State": "CO", "PostCode": 123 } ]

Error

fork/exec /home/sftp_user/uploads/json2html.py: exec format error

Any idea on what might be the issue in the code?

2

Answers


  1. Chosen as BEST ANSWER

    After hours of troubleshooting, found out that the script file name - "json2html.py" was causing the issue (conflicting with the package name - json2html). After changing the script file name, the script started working.


  2. Seems that the problem with null value in your input JSON.
    Try to convert it first to None and then it should be fine

    from json2html import *
    data = [ { "FirstName": "John", "LastName": "Doe", "StreetName": "120 jefferson st.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Jack", "LastName": "McGinnis", "StreetName": "220 hobo Av.", "County": "Phila", "State": " PA", "PostCode": 9119 }, { "FirstName": "John "Da Man"", "LastName": "Repici", "StreetName": "120 Jefferson St.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Stephen", "LastName": "Tyler", "StreetName": "7452 Terrace "At the Plaza" road", "County": "SomeTown", "State": "SD", "PostCode": 91234 }, { "FirstName": None, "LastName": "Blankman", "StreetName": None, "County": "SomeTown", "State": " SD", "PostCode": 298 }, { "FirstName": "Joan "the bone", Anne", "LastName": "Jet", "StreetName": "9th, at Terrace plc", "County": "Desert City", "State": "CO", "PostCode": 123 } ]
    res = json2html.convert(json={"data": data})
    print(res)
    

    Output:

    <table border="1"><tr><th>data</th><td><table border="1"><thead><tr><th>FirstName</th><th>LastName</th><th>StreetName</th><th>County</th><th>State</th><th>PostCode</th></tr></thead><tbody><tr><td>John</td><td>Doe</td><td>120 jefferson st.</td><td>Riverside</td><td> NJ</td><td>8075</td></tr><tr><td>Jack</td><td>McGinnis</td><td>220 hobo Av.</td><td>Phila</td><td> PA</td><td>9119</td></tr><tr><td>John &quot;Da Man&quot;</td><td>Repici</td><td>120 Jefferson St.</td><td>Riverside</td><td> NJ</td><td>8075</td></tr><tr><td>Stephen</td><td>Tyler</td><td>7452 Terrace &quot;At the Plaza&quot; road</td><td>SomeTown</td><td>SD</td><td>91234</td></tr><tr><td>None</td><td>Blankman</td><td>None</td><td>SomeTown</td><td> SD</td><td>298</td></tr><tr><td>Joan &quot;the bone&quot;, Anne</td><td>Jet</td><td>9th, at Terrace plc</td><td>Desert City</td><td>CO</td><td>123</td></tr></tbody></table></td></tr></table>
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search