I have a python script that work's perfectly well on a windows OS.
I want to run the same script on a Linux/Ubuntu machine. I changed the parameters that differ, such as... paths/directories, as well as interpreter from python.exe to python3.
Nonetheless, once I run the script I get an error within a function that works just fine on windows. The function is an API call, in essence it calls another python script with pre-defined parameters in json and reads the output from the shell.
script_path = "/home/user/some_path_here/filename"
def ReportsByDate(date = today):
new_report = subprocess.Popen([
"python3",
script_path,
"reports/list",
json.dumps({"date": today}),
"pretty",
], shell=True, stdout=subprocess.PIPE)
output = new_report.communicate()[0]
output = json.loads(output)
global df
df = pd.DataFrame(output)
return(df)
The error I am getting is:
Traceback (most recent call last):
File "prod_get_today.py", line 118, in <module>
ReportsByDate()
File "prod_get_today.py", line 72, in ReportsByDate
output = json.loads(output)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
My assumption is that either:
- The interpreter is not called properly, or
- The data from the shell should be read differently in linux vs. windows
Any ideas what might be the problem?
stderr, so it can't be read from the communicate pipe.