Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check and convert command line parameter for windows #9

Closed
gitnol opened this issue May 21, 2022 · 4 comments
Closed

check and convert command line parameter for windows #9

gitnol opened this issue May 21, 2022 · 4 comments

Comments

@gitnol
Copy link

gitnol commented May 21, 2022

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)

with open(args.output, 'r') as f:

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, in 
  File "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
@Ximaz
Copy link

Ximaz commented Jan 11, 2025

Could you share the D:\Downloads\flows_schema.yml file you're trying to parse ? I don't believe the solution is to replace the \ by / in the args.output string. I think it's inside the file itself that you must fix the slashes, as the file by itself is read correctly. I believe It's its content which is guilty here.

@Ximaz
Copy link

Ximaz commented Jan 11, 2025

I read more in details about the traceback and I don't even think it's about a slash issue.

The last line of the traceback gives you a hint : what's at 87th line in your YAML file ? It seems to expect a key: value line, but you don't provide it. Try to fix the syntax first, it should resolve the issue.

@gitnol
Copy link
Author

gitnol commented Jan 11, 2025

It is 3 years old now. Maybe you close this issue. :)

@Ximaz
Copy link

Ximaz commented Jan 18, 2025

To be honest, I did not even look for the date, thought that if someone ran the same issue, they could try to troubleshoot too.

I believe as you are the author of this issue, you can close it. I don't have the permissions to do that.

@gitnol gitnol closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants