Hello I am trying to execute a python script in the Ubuntu subsystem I enabled in Windows.
The reason I want to do this is because I have scheduled with crontab to run this script daily.
The problem I have is that the same script that passes when I run on normal Windows terminal fails on the ubuntu terminal. I am executing with Pyhon3 in both cases.
The problem seems to be related to how I am processing the json data.
What the code does is to get the response an API call returns, add add its contents in an excel file with the help of the tablib library which I have installed.
call_api_call method returns the json in this form: return json.loads(response.text)
Related Part of Code:
dataset_list = call_api_call()
data = tablib.Dataset()
data.json = json.dumps(dataset_list)
data_export = data.export('xlsx')
filename = os.path.dirname(os.path.realpath(__file__)) + '_' + str(datetime.date.today()) + '.xlsx'
with open(filename, 'wb') as f:
f.write(data_export) # write issues to the xlsx file
Running from Windows on an Ubuntu terminal:
Execute with:
python3 /mnt/c/Users/marialena/source/repos/GitLab_Issues/gitlab.py -vs
Output:
Traceback (most recent call last):
File "/mnt/c/Users/marialena/source/repos/GitLab_Issues/gitlab.py", line 93, in <module>
data1 = json.loads(list_with_bugs)
File "/usr/lib/python3.6/json/__init__.py", line 348, in loads
'not {!r}'.format(s.__class__.__name__))
TypeError: the JSON object must be str, bytes or bytearray, not 'dict'
Running from Windows normal terminal:
Execute with:
PS C:\Users\marialena\source\repos\GitLab_Issues> python .\gitlab.py
Output: No error, File gets created with no issue.
Update:
I have updated python from 3.6.8 to 3.7.3 in the unix subsystem using the following command to match the windows version (after i have installed again tablib with python3.7 -m pip install tablib)
python3.7 /mnt/c/Users/marialena/source/repos/GitLab_Issues/gitlab.py -vs
When I execute now the script I get
Traceback (most recent call last):
File "/mnt/c/Users/marialena/source/repos/GitLab_Issues/gitlab.py", line 93, in <module>
data.json = json.dumps(list_with_bugs)
File "/usr/local/lib/python3.7/dist-packages/tablib/formats/_json.py", line 39, in import_set
dset.dict = json.loads(in_stream)
File "/usr/local/lib/python3.7/dist-packages/tablib/core.py", line 381, in _set_dict
if isinstance(pickle[0], list):
KeyError: 0
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/mnt/c/Users/marialena/source/repos/GitLab_Issues/gitlab.py", line 93, in <module>
data.json = json.dumps(list_with_bugs)
File "/usr/local/lib/python3.7/dist-packages/tablib/formats/_json.py", line 39, in import_set
dset.dict = json.loads(in_stream)
File "/usr/local/lib/python3.7/dist-packages/tablib/core.py", line 381, in _set_dict
if isinstance(pickle[0], list):
KeyError: 0