mitmproxy2swagger
mitmproxy2swagger copied to clipboard
check and convert command line parameter for windows
Hi,
On windows, an error occurs in mitmproxy2swagger.py line 63 because yaml.load(f) does not like the backslash in the f string (the input parameter -o) https://github.com/alufers/mitmproxy2swagger/blob/fd382ed94d23ca9eea6eda55d7f39c85a1f885e5/mitmproxy2swagger/mitmproxy2swagger.py#L62
mitmproxy2swagger -i "D:\Downloads\flows" -o "D:\Downloads\flows_schema.yml" -p https://my.site.com
If you change it to a slash, there is no problem and it works like intended.
mitmproxy2swagger -i "D:/Downloads/flows" -o "D:/Downloads/flows_schema.yml" -p https://my.site.com
Therefore, my suggestion/solution is to replace '' with '/'
import os args.output = arg.output.replace(os.sep, '/') args.input = args.input.replace(os.sep, '/')
Traceback:
Traceback (most recent call last): File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\Scripts\mitmproxy2swagger.exe\__main__.py", line 7, inFile "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\mitmproxy2swagger\mitmproxy2swagger.py", line 63, in main swagger = yaml.load(f) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\main.py", line 434, in load return constructor.get_single_data() File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\constructor.py", line 119, in get_single_data node = self.composer.get_single_node() File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 76, in get_single_node document = self.compose_document() File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 99, in compose_document node = self.compose_node(None, None) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 143, in compose_node node = self.compose_mapping_node(anchor) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 223, in compose_mapping_node item_value = self.compose_node(node, item_key) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 141, in compose_node node = self.compose_sequence_node(anchor) File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\composer.py", line 184, in compose_sequence_node while not self.parser.check_event(SequenceEndEvent): File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\parser.py", line 146, in check_event self.current_event = self.state() File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\parser.py", line 565, in parse_indentless_sequence_entry if not self.scanner.check_token( File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\scanner.py", line 1794, in check_token while self.need_more_tokens(): File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\scanner.py", line 211, in need_more_tokens self.stale_possible_simple_keys() File "C:\Users\redacted\AppData\Local\Programs\Python\Python310\lib\site-packages\ruamel\yaml\scanner.py", line 360, in stale_possible_simple_keys raise ScannerError( ruamel.yaml.scanner.ScannerError: while scanning a simple key in "D:\Downloads\flows_schema.yml", line 86, column 1 could not find expected ':' in "D:\Downloads\flows_schema.yml", line 87, column 1