My python progam is creating wrong file path.
The file path formed is wrong : ‘/autocameratest2dataTestImages/7_vw_test.png’
The correct file path should be: ‘/autocameratest2/data/TestImages/7_vw_test.png’
The file path is fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/autocameratest2\data\TestImages/7_vw_test.png'
172.17.0.1 - - [05/Feb/2022 17:34:22] "POST /places?camid=1&image1test=7_vw_test.png&image2perfect=5_vw_master.png HTTP/1.1" 500 -
In the python api program, the below URL
http://127.0.0.1:5000/places?camid=1&image1test=7_vw_test.png&image2perfect=5_vw_master.png
returns a json file. The code works fine in VisualStudio code or outside docker. It python code give a path problem inside docker.
image1test_path = os.path.join(IMAGE_FOLD_PATH,'autocameratest2dataTestImages',image1test)
image2perfect_path = os.path.join(IMAGE_FOLD_PATH,'autocameratest2dataTestImages',image2perfect)
test_results = generate_report(camid, image1test_path, image2perfect_path)
test_names = ['CamId','Blur','check_scale','noise','scrolled','allign','mirror','blackspots','ssim_score','staticlines','rotation_deg']
2
Answers
The following approach helped my create a file path that I wanted. like this "/autocameratest2/data/TestImages"
Other techniques which I tried for building the path is below. These are good though it did not solve my problme.
Use pathlib, python’s path parsing library, it has linux, windows type paths. You can freely manipulate between them.
Your problem is that docker runs on linux unless told otherwise, linux uses / for path and windows , thus the issue.
pathlib.Path will help you.