0

Hello currently I was developing some a python script on Repl.it for sake for devices sharing.

But now considering I am moving towards Visual Studio (for the toolbox and other mattersà and I have copied over the code, I get an Invalid Argument code for me that does not make any sense.

Loaded '__main__'
Loaded 'runpy'
Traceback (most recent call last):
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\joeri\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 167, in <module>
The thread 'MainThread' (0x1) has exited with code 0 (0x0).
    fetch_points(api_response_url)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 107, in fetch_points
    save_jsonfile(folder_path, "points", text)
  File "D:\Programmeer portfolio\Programma's\Python Scripts\PythonApplicationGIPODAPITest\PythonApplicationGIPODAPITest.py", line 156, in save_jsonfile
    file1 = open(completeName, "wt")
OSError: [Errno 22] Invalid argument: 'api_request_jsons\x0cetch_points\\points.json'
The program 'python.exe' has exited with code 1 (0x1).

If the code can work on repl.it and I have the same file and folder structure..then why does this not work in Visual Studio? Sure repl.it has python 3.8 and Visual Studio has python 3.7..But that could not be it right?

Edited: Code deleted for privacy reasons.

enter image description here

ThunderSpark
  • 89
  • 2
  • 13

1 Answers1

0

You've moved from linux-based file structure on repl.it which uses a forward slash / to delineate folders, like api_request_jsons/fetch_points to a Windows-based file structure on your local machine (which is running windows) which uses a backslash \ to delineate folders. So api_request_jsons/fetch_points needs to be converted to api_request_jsons\fetch_points. The best way to do this is to use os.path.join with each nested folder as arguments (i.e. replace api_request_jsons\fetch_points with os.path.join("api_request_jsons", "fetch_points") to allow your code to transfer between *nix and Windows file systems.

Cameron McFee
  • 386
  • 1
  • 4
  • No, this is not the case. Windows works just fine with forward slashes, and of course URLs are always forward slashes. In the error, it's clear that he DOES have a literal string with a backslash, because \f becomes the ASCII character 0x0C, as in the error. If you have converted your strings to backslashes, change them back. – Tim Roberts Feb 24 '21 at 21:17
  • If you seen my code I kind of already use Os Path Join for the save file function but thank you anyways. I have replaced my variables with you sollution and it seems to work fine. Thank you. Thouhg one small notice though I cannot seem to see the JSON files in the Solution Explorer this program generates. – ThunderSpark Feb 24 '21 at 21:20