Code Monkey home page Code Monkey logo

mitmproxy2swagger's Introduction

mitmproxy2swagger

PyPI version Arch Linux repository

video.mp4

A tool for automatically converting mitmproxy captures to OpenAPI 3.0 specifications. This means that you can automatically reverse-engineer REST APIs by just running the apps and capturing the traffic.


🆕 NEW!

Added support for processing HAR exported from the browser DevTools. See Usage - HAR for more details.


Installation

First you will need python3 and pip3.

$ pip install mitmproxy2swagger
# ... or ...
$ pip3 install mitmproxy2swagger
# ... or ...
$ git clone [email protected]:alufers/mitmproxy2swagger.git
$ cd mitmproxy2swagger
$ docker build -t mitmproxy2swagger .

Then clone the repo and run mitmproxy2swagger as per examples below.

Usage

Mitmproxy

To create a specification by inspecting HTTP traffic you will need to:

  1. Capture the traffic by using the mitmproxy tool. I personally recommend using mitmweb, which is a web interface built-in to mitmproxy.

    $ mitmweb
    Web server listening at http://127.0.0.1:8081/
    Proxy server listening at http://*:9999
    ...

    IMPORTANT

    To configure your client to use the proxy exposed by mitm proxy, please consult the mitmproxy documentation for more information.

  2. Save the traffic to a flow file.

    In mitmweb you can do this by using the "File" menu and selecting "Save":

    A screenshot showing the location of the "Save" option in the "File" menu

  3. Run the first pass of mitmproxy2swagger:

    $ mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix>
    # ... or ...
    $ docker run -it -v $PWD:/app mitmproxy2swagger mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix>

    Please note that you can use an existing schema, in which case the existing schema will be extended with the new data. You can also run it a few times with different flow captures, the captured data will be safely merged.

    <api_prefix> is the base url of the API you wish to reverse-engineer. You will need to obtain it by observing the requests being made in mitmproxy.

    For example if an app has made requests like these:

    https://api.example.com/v1/login
    https://api.example.com/v1/users/2
    https://api.example.com/v1/users/2/profile

    The likely prefix is https://api.example.com/v1.

  4. Running the first pass should have created a section in the schema file like this:

    x-path-templates:
      # Remove the ignore: prefix to generate an endpoint with its URL
      # Lines that are closer to the top take precedence, the matching is greedy
      - ignore:/addresses
      - ignore:/basket
      - ignore:/basket/add
      - ignore:/basket/checkouts
      - ignore:/basket/coupons/attach/{id}
      - ignore:/basket/coupons/attach/104754

    You should edit the schema file with a text editor and remove the ignore: prefix from the paths you wish to be generated. You can also adjust the parameters appearing in the paths.

  5. Run the second pass of mitmproxy2swagger:

    $ mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix> [--examples]
    # ... or ...
    $ docker run -it -v $PWD:/app mitmproxy2swagger mitmproxy2swagger -i <path_to_mitmptoxy_flow> -o <path_to_output_schema> -p <api_prefix> [--examples]

    Run the command a second time (with the same schema file). It will pick up the edited lines and generate endpoint descriptions.

    Please note that mitmproxy2swagger will not overwrite existing endpoint descriptions, if you want to overwrite them, you can delete them before running the second pass.

    Passing --examples will add example data to requests and responses. Take caution when using this option, as it may add sensitive data (tokens, passwords, personal information etc.) to the schema. Passing --headers will add headers data to requests and responses. Take caution when using this option, as it may add sensitive data (tokens, passwords, personal information etc.) to the schema.

HAR

  1. Capture and export the traffic from the browser DevTools.

    In the browser DevTools, go to the Network tab and click the "Export HAR" button.

    A screenshot showing where the export har button is located

  2. Continue the same way you would do with the mitmproxy dump. mitmproxy2swagger will automatically detect the HAR file and process it.

Example output

See the examples. You will find a generated schema there and an html file with the generated documentation (via redoc-cli).

See the generated html file here.

Development and contributing

This project uses:

To install the dependencies:

poetry install

Run linters:

pre-commit run --all-files

Install pre-commit hooks:

pre-commit install

Run tests:

poetry run pytest

Run tests with coverage:

poetry run pytest --cov=mitmproxy2swagger

License

MIT

mitmproxy2swagger's People

Contributors

alufers avatar corrupted-bios avatar dependabot[bot] avatar fabaff avatar gadcam avatar jwilk avatar k0rshak avatar kpcyrd avatar kuba2k2 avatar nsna avatar pre-commit-ci[bot] avatar puc9 avatar rhoggs-bot-test-account avatar scw007 avatar sh4rk avatar timvahlbrock avatar tweska avatar victorlpgazolli avatar willtrnr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mitmproxy2swagger's Issues

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)

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

HAR from Firefox not loaded

When I try to process a HAR from Firefox I get "Flow file corrupted: Invalid data format."

.local/bin/mitmproxy2swagger -i www.google.com_Archive\ \[22-06-06\ 18-09-31\].har -o temp -p https://www.google.com
No existing swagger file found. Creating new one.
Flow file corrupted: Invalid data format.
Done!

www.google.com_Archive [22-06-06 18-09-31].zip

I did an example with Google search. See attached file.

Cannot convert - TypeError: 'int' object is not subscriptable

Per the title, when I try to convert a flow to Swagger using mitmproxy2swagger -i flows -o schema.yml -p api, I get the following error:

No existing swagger file found. Creating new one.
Traceback (most recent call last):
  File "/opt/homebrew/bin/mitmproxy2swagger", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 168, in main
    for req in capture_reader.captured_requests():
  File "/opt/homebrew/lib/python3.11/site-packages/mitmproxy2swagger/har_capture_reader.py", line 114, in captured_requests
    for entry in data["log"]["entries"].persistent():
                 ~~~~^^^^^^^
TypeError: 'int' object is not subscriptable

Installed via pip3 install mitmproxy2swagger

feature request: use `additionalProperties` for dicts with generic keys

Currently, every object will be explicitly mapped out. However, sometimes the keys are generic and depending on the data of the user (e.g. when the keys are ids of some objects). In this case OpenAPIs additionalProperties option could be used instead. Detecting generic keys is not trivial not finally solvable, but some types of generic keys like numbers only or UUIDs could be easily detected.

I am willing to create a PR for this.

Second time run of the tool gives an error

Traceback (most recent call last):
File "/opt/homebrew/bin/mitmproxy2swagger", line 8, in
sys.exit(main())
File "/opt/homebrew/lib/python3.10/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 125, in main
path_template_regexes = [re.compile(path_to_regex(path))
File "/opt/homebrew/lib/python3.10/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 125, in
path_template_regexes = [re.compile(path_to_regex(path))
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/re.py", line 251, in compile
return _compile(pattern, flags)
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/re.py", line 303, in _compile
p = sre_compile.compile(pattern, flags)
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/sre_compile.py", line 788, in compile
p = sre_parse.parse(p, flags)
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 955, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 444, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 843, in _parse
raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 35

image

Nothing shows up in the output file

Hi,

I have installed mitmproxy and mitmproxy2swagger in a virtual environment. I can run your software without errors but nothing interesting shows up in the output file.

Command I used:

$ mitmproxy2swagger -i flows -o specs.yml -p https://api.example.com -f flow
No existing swagger file found. Creating new one.
[▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌▌] 100.0%Done!

Contents of the output file:

$ cat specs.yml 
openapi: 3.0.0
info:
  title: flows Mitmproxy2Swagger
  version: 1.0.0
servers:
- url: https://api.example.com
  description: The default server
paths: {}
x-path-templates:
# Remove the ignore: prefix to generate an endpoint with its URL
# Lines that are closer to the top take precedence, the matching is greedy
  []

Version info:

$ python --version
Python 3.9.5

$ mitmproxy --version
Mitmproxy: 9.0.1
Python:    3.9.5
OpenSSL:   OpenSSL 3.0.7 1 Nov 2022
Platform:  Linux-5.4.0-144-generic-x86_64-with-glibc2.31

$ pip list | grep mitmproxy2swagger
mitmproxy2swagger        0.8.2

bash: mitmproxy2swagger: command not found

After installing with git clone https://github.com/alufers/mitmproxy2swagger.git . I try running the sudo docker build -t mitmproxy2swagger .
and got the error below right after the process is complete.

ERROR: Could not build wheels for aioquic, which is required to install pyproject.toml-based projects
The command '/bin/sh -c poetry export -f requirements.txt | /venv/bin/pip install -r /dev/stdin' returned a non-zero code: 1

Error with good mitmproxy version : "Flow file corrupted: mitmproxy 8.1.1 cannot read files with flow format version 18, please update mitmproxy"

Hello,

I have a problem to install mitmproxy2swagger on my computer (I tried for 1 and half hour). It gives me the following error : "Flow file corrupted: mitmproxy 8.1.1 cannot read files with flow format version 18, please update mitmproxy".

Btw, it don't recognize my command when I try with sudo and my mitmproxy version is :
Mitmproxy: 9.0.1

Thanks

ValueError: Unknown operator when using flow file which contains content length information

Hey there, great tool. I am stoked to try it out.
I've run into a problem though in the following way

  1. capture one request using mitmweb
  2. save flow file (file name 'flows')
  3. run mitmproxy2swagger -i flows -o schema -p https://redacted.redacted/

result:
No existing swagger file found. Creating new one. Traceback (most recent call last): File "/home/redacted/.local/bin/mitmproxy2swagger", line 8, in <module> sys.exit(main()) File "/home/redacted/.local/lib/python3.10/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 121, in main for f in caputre_reader.captured_requests(): File "/home/redacted/.local/lib/python3.10/site-packages/mitmproxy2swagger/har_capture_reader.py", line 87, in captured_requests data = json_stream.load(f) File "/usr/lib/python3.10/site-packages/json_stream/loader.py", line 8, in load return StreamingJSONBase.factory(token, token_stream, persistent) File "/usr/lib/python3.10/site-packages/json_stream/base.py", line 28, in factory raise ValueError(f"Unknown operator {token}") # pragma: no cover ValueError: Unknown operator 9613

interpretation:
The flow file itself uses a human readable format which incorporates content length information in addition to the request/response json data. The symbols the json parser is complaining about are the very first few characters of the flow file 9613:4:type;4:http;7 ... 3880:{"httpstatuscode":"200","statusmessage":"OK" ... 16:certificate_list;1462:1456:-----BEGIN CERTIFICATE----- ...

question:
What is the reason for the format mismatch? Where did I fuck up?

context:
Arch Linux, up to date
mitmweb --version Mitmproxy: 8.1.0 Python: 3.10.5 OpenSSL: OpenSSL 1.1.1o 3 May 2022 Platform: Linux-5.18.5-arch1-1-x86_64-with-glibc2.35
mitmproxy2swagger: seems to happen with both the arch linux package (v0.6.1) and the version installed using pip install mitmproxy2swagger

Cheers!

mitmproxy2swagger stuck

Hi, I tried to run this code
sudo mitmproxy2swagger -i ~/Downloads/flows -o spec.yml -p http://127.0.0.1:8888 -f flow --examples
And this was the output
[sudo] password for hapihacker:
No existing swagger file found. Creating new one.
[ ] 0.0%

The program remains stuck and does not generate any spec.yml file.
Any solution?

MITMPROXY VERSION
mitmweb --version
Mitmproxy: 10.1.5
Python: 3.11.7
OpenSSL: OpenSSL 3.1.4 24 Oct 2023
Platform: Linux-6.5.0-kali3-amd64-x86_64-with-glibc2.37

AttributeError: 'str' object has no attribute 'removeprefix'

printf "Hello World!\n"

I'm using mitmproxy2swagger on my Ubuntu 20.04 WSL instance and I'm running into a python error when running mitmproxy2swagger when using a HAR file.

Complete command and output:

pieter@supersecretstation:/downloads$ mitmproxy2swagger -i somefile.har -o outputfile -p https://sub.domain.tld
No existing swagger file found. Creating new one.
[                              ] 0.0%Traceback (most recent call last):
  File "/mnt/c/Users/Pieter/.local/bin/mitmproxy2swagger", line 8, in <module>
    sys.exit(main())
  File "/mnt/c/Users/Pieter/.local/lib/python3.8/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 116, in main
    path = strip_query_string(url).removeprefix(args.api_prefix)
AttributeError: 'str' object has no attribute 'removeprefix'

Maybe I'm running the wrong version of python?

Thanks!

exit 0

Output file is empty

Hello, I'm using the command:
sudo mitmproxy2swagger -i ~/Downloads/flows -o ~/Downloads/spec.yml -p http://crapi.apisec.ai -f flow
The flows file seems fine, but the resulting spec.yml has no api paths whatsoever.
Here is the content of the output file:
Screenshot 2023-06-08 180532

TypeError: 'int' object is not subscriptable

I'm getting this error when trying to use mitmproxy2swagger

PS C:\MyDartProjects\new_sali\backend\doc\swagger>  pip install mitmproxy2swagger
Requirement already satisfied: mitmproxy2swagger in c:\python312\lib\site-packages (0.11.0)
Requirement already satisfied: json-stream<3.0.0,>=2.3.2 in c:\python312\lib\site-packages (from mitmproxy2swagger) (2.3.2)
Requirement already satisfied: mitmproxy<11.0.0,>=10.0.0 in c:\python312\lib\site-packages (from mitmproxy2swagger) (10.1.1)
Requirement already satisfied: ruamel.yaml<0.18.0,>=0.17.32 in c:\python312\lib\site-packages (from mitmproxy2swagger) (0.17.35)
Requirement already satisfied: json-stream-rs-tokenizer>=0.4.17 in c:\python312\lib\site-packages (from json-stream<3.0.0,>=2.3.2->mitmproxy2swagger) (0.4.25)
Requirement already satisfied: aioquic-mitmproxy<0.10,>=0.9.20 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.9.20.3)
Requirement already satisfied: asgiref<3.8,>=3.2.10 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (3.7.2)
Requirement already satisfied: Brotli<1.1,>=1.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.0.9)
Requirement already satisfied: certifi>=2019.9.11 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2023.7.22)
Requirement already satisfied: cryptography<41.1,>=38.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (41.0.4)
Requirement already satisfied: flask<2.4,>=1.1.1 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.3.3)
Requirement already satisfied: h11<0.15,>=0.11 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.14.0)
Requirement already satisfied: h2<5,>=4.1 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (4.1.0)
Requirement already satisfied: hyperframe<7,>=6.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (6.0.1)
Requirement already satisfied: kaitaistruct<0.11,>=0.10 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.10)
Requirement already satisfied: ldap3<2.10,>=2.8 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.9.1)
Requirement already satisfied: mitmproxy-rs<0.4,>=0.3.6 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.3.11)
Requirement already satisfied: msgpack<1.1.0,>=1.0.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.0.7)
Requirement already satisfied: passlib<1.8,>=1.6.5 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.7.4)
Requirement already satisfied: protobuf<5,>=3.14 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (4.24.4)
Requirement already satisfied: pyOpenSSL<23.3,>=22.1 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (23.2.0)
Requirement already satisfied: pyparsing<3.2,>=2.4.2 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (3.1.1)
Requirement already satisfied: pyperclip<1.9,>=1.6.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.8.2)
Requirement already satisfied: sortedcontainers<2.5,>=2.3 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.4.0)
Requirement already satisfied: tornado<7,>=6.2 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (6.3.3)
Requirement already satisfied: urwid-mitmproxy<2.2,>=2.1.1 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.1.2.1)
Requirement already satisfied: wsproto<1.3,>=1.0 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.2.0)
Requirement already satisfied: publicsuffix2<3,>=2.20190812 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.20191221)
Requirement already satisfied: zstandard<0.22,>=0.11 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.21.0)
Requirement already satisfied: pydivert<2.2,>=2.0.3 in c:\python312\lib\site-packages (from mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.1.0)
Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in c:\python312\lib\site-packages (from ruamel.yaml<0.18.0,>=0.17.32->mitmproxy2swagger) (0.2.8)
Requirement already satisfied: pylsqpack<0.4.0,>=0.3.3 in c:\python312\lib\site-packages (from aioquic-mitmproxy<0.10,>=0.9.20->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.3.17)
Requirement already satisfied: cffi>=1.12 in c:\python312\lib\site-packages (from cryptography<41.1,>=38.0->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.16.0)
Requirement already satisfied: Werkzeug>=2.3.7 in c:\python312\lib\site-packages (from flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (3.0.0)
Requirement already satisfied: Jinja2>=3.1.2 in c:\python312\lib\site-packages (from flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (3.1.2)
Requirement already satisfied: itsdangerous>=2.1.2 in c:\python312\lib\site-packages (from flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.1.2)
Requirement already satisfied: click>=8.1.3 in c:\python312\lib\site-packages (from flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in c:\python312\lib\site-packages (from flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (1.6.3)
Requirement already satisfied: hpack<5,>=4.0 in c:\python312\lib\site-packages (from h2<5,>=4.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (4.0.0)
Requirement already satisfied: pyasn1>=0.4.6 in c:\python312\lib\site-packages (from ldap3<2.10,>=2.8->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.5.0)
Requirement already satisfied: mitmproxy_windows==0.3.11 in c:\python312\lib\site-packages (from mitmproxy-rs<0.4,>=0.3.6->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.3.11)
Requirement already satisfied: pycparser in c:\python312\lib\site-packages (from cffi>=1.12->cryptography<41.1,>=38.0->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.21)
Requirement already satisfied: colorama in c:\python312\lib\site-packages (from click>=8.1.3->flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (0.4.6)
Requirement already satisfied: MarkupSafe>=2.0 in c:\python312\lib\site-packages (from Jinja2>=3.1.2->flask<2.4,>=1.1.1->mitmproxy<11.0.0,>=10.0.0->mitmproxy2swagger) (2.1.3)
PS C:\MyDartProjects\new_sali\backend\doc\swagger> 



PS C:\MyDartProjects\new_sali\backend\doc\swagger> python --version
Python 3.12.0

PS C:\MyDartProjects\new_sali\backend\doc\swagger> mitmproxy2swagger -i .\flows -o ./out.yaml  -p http://localhost:3350/api/v1
No existing swagger file found. Creating new one.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\python312\Scripts\mitmproxy2swagger.exe\__main__.py", line 7, in <module>
  File "C:\python312\Lib\site-packages\mitmproxy2swagger\mitmproxy2swagger.py", line 178, in main
    for req in capture_reader.captured_requests():
  File "C:\python312\Lib\site-packages\mitmproxy2swagger\har_capture_reader.py", line 117, in captured_requests
    for entry in data["log"]["entries"].persistent():
                 ~~~~^^^^^^^
TypeError: 'int' object is not subscriptable
PS C:\MyDartProjects\new_sali\backend\doc\swagger> 

flows

3241:9:websocket;0:~8:response;1396:6:reason;2:OK,11:status_code;3:200#13:timestamp_end;18:1697032225.7566624^15:timestamp_start;18:1697032225.7546453^8:trailers;0:~7:content;856:{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImFub19leGVyY2ljaW8iOiIyMDIzIiwiYW5vX2V4ZXJjaWNpb19zZXRvciI6IjIwMDMiLCJjb2RfZGVwYXJ0YW1lbnRvIjoyLCJjb2Rfb3JnYW8iOjIsImNvZF9zZXRvciI6MSwiY29kX3VuaWRhZGUiOjg5LCJjcGYiOiIxMzEyODI1MDczMSIsImlkX3NldG9yIjo1MjQsIm5vbV9jZ20iOiJJc2FxdWUgTmV2ZXMgU2FudCdhbmEiLCJudW1jZ20iOjE0MDA1MCwidXNlcm5hbWUiOiJpc2FxdWUuc2FudGFuYSJ9LCJleHAiOjE2OTcwNjQ2MjUsImlhdCI6MTY5NzAzMjIyNSwiaXNzIjoibmV3c2FsaS5yaW9kYXNvc3RyYXMucmouZ292LmJyIiwibmJmIjoxNjk3MDMyMjI1fQ.wUxQI1alM0A3638c1Yx01Y3NgTttaK_3zrnYcVVZvuw","nom_cgm":"Isaque Neves Sant'ana","cpf":"13128250731","numcgm":140050,"username":"isaque.santana","ano_exercicio":"2023","cod_setor":1,"id_setor":524,"cod_orgao":2,"cod_unidade":89,"cod_departamento":2,"nom_setor":"TI - Tecnologia da Informação","expiry":"2023-10-11T19:50:25.738848","ano_exercicio_setor":"2003"},7:headers;354:40:4:date,29:Wed, 11 Oct 2023 13:50:25 GMT,]35:27:access-control-allow-origin,1:*,]31:17:transfer-encoding,7:chunked,]37:29:access-control-expose-headers,1:*,]33:15:x-frame-options,10:SAMEORIGIN,]51:12:content-type,31:application/json; charset=utf-8,]37:16:x-xss-protection,13:1; mode=block,]36:22:x-content-type-options,7:nosniff,]18:6:server,6:Angel3,]]12:http_version;8:HTTP/1.1,}7:request;650:4:path;18:/api/v1/auth/login,9:authority;0:,6:scheme;4:http,6:method;4:POST,4:port;4:3350#4:host;9:localhost;13:timestamp_end;17:1697032225.544109^15:timestamp_start;18:1697032225.5431092^8:trailers;0:~7:content;97:{
    "username": "isaque.santana",
    "password": "Ins257257",
    "anoExercicio": "2023"
},7:headers;295:36:12:Content-Type,16:application/json,]39:10:User-Agent,21:PostmanRuntime/7.33.0,]15:6:Accept,3:*/*,]57:13:Postman-Token,36:c05dd98c-acad-4ded-8773-800c07217fef,]25:4:Host,14:localhost:3350,]40:15:Accept-Encoding,17:gzip, deflate, br,]28:10:Connection,10:keep-alive,]23:14:Content-Length,2:97,]]12:http_version;8:HTTP/1.1,}6:backup;0:~17:timestamp_created;18:1697032225.5431092^7:comment;0:;8:metadata;0:}6:marked;0:;9:is_replay;0:~11:intercepted;5:false!11:server_conn;469:3:via;0:~19:timestamp_tcp_setup;16:1697032225.55111^7:address;19:9:localhost;4:3350#]19:timestamp_tls_setup;0:~13:timestamp_end;17:1697032478.893024^15:timestamp_start;18:1697032225.5461097^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:baac6dca-5915-47e3-a56f-476efb33582a;8:sockname;22:3:::1;5:22274#1:0#1:0#]8:peername;21:3:::1;4:3350#1:0#1:0#]}11:client_conn;422:10:proxy_mode;7:regular;8:mitmcert;0:~19:timestamp_tls_setup;0:~13:timestamp_end;18:1697033078.8951516^15:timestamp_start;17:1697032225.540111^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:bbe98b4a-9ed6-4457-9fd3-e94cca252722;8:sockname;21:3:::1;4:8080#1:0#1:0#]8:peername;22:3:::1;5:22273#1:0#1:0#]}5:error;0:~2:id;36:26224f55-7ab1-438e-94b7-98b73e7b793c;4:type;4:http;7:version;2:20#}3790:9:websocket;0:~8:response;1536:6:reason;2:OK,11:status_code;3:200#13:timestamp_end;18:1697032303.2793176^15:timestamp_start;18:1697032303.2773159^8:trailers;0:~7:content;996:{"cod_processo":8,"ano_exercicio":"2004","cod_classificacao":40,"cod_assunto":2,"numcgm":699,"cod_usuario":161,"cod_situacao":11,"timestamp":"2004-01-05T10:27:24.229Z","observacoes":"","confidencial":true,"resumo_assunto":"","id_setor":null,"atributosProtocolo":[{"cod_atributo":1,"nom_atributo":"Anotações","tipo":"t","valor_padrao":"","cod_assunto":2,"cod_classificacao":40,"cod_processo":8,"exercicio":"2004","valor":""},{"cod_atributo":2,"nom_atributo":"Referência Anterior","tipo":"t","valor_padrao":"","cod_assunto":2,"cod_classificacao":40,"cod_processo":8,"exercicio":"2004","valor":""}],"cgm_interessado":699,"nome_interessado":"NAIR IVETE DOS REIS","codigo_processo":"8/2004","nom_classificacao":"Férias","nom_assunto":"Férias","nom_situacao":"Arquivado férias","usuario_que_incluiu":"dbertin","nome_usuario_que_incluiu":"DENIZE MOREIRA DE AZEVEDO BERTIN","cod_ultimo_andamento":9,"tipo_interessado":"i","timestamp_arquivamento":"2004-02-03T14:47:59.131Z","texto_complementar":""},7:headers;354:40:4:date,29:Wed, 11 Oct 2023 13:51:43 GMT,]35:27:access-control-allow-origin,1:*,]31:17:transfer-encoding,7:chunked,]37:29:access-control-expose-headers,1:*,]33:15:x-frame-options,10:SAMEORIGIN,]51:12:content-type,31:application/json; charset=utf-8,]37:16:x-xss-protection,13:1; mode=block,]36:22:x-content-type-options,7:nosniff,]18:6:server,6:Angel3,]]12:http_version;8:HTTP/1.1,}7:request;1058:4:path;34:/api/v1/protocolo/processos/2004/8,9:authority;0:,6:scheme;4:http,6:method;3:GET,4:port;4:3350#4:host;9:localhost;13:timestamp_end;18:1697032302.8685155^15:timestamp_start;18:1697032302.8675468^8:trailers;0:~7:content;0:,7:headers;785:552:13:Authorization,530:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImFub19leGVyY2ljaW8iOiIyMDIzIiwiYW5vX2V4ZXJjaWNpb19zZXRvciI6IjIwMDMiLCJjb2RfZGVwYXJ0YW1lbnRvIjoyLCJjb2Rfb3JnYW8iOjIsImNvZF9zZXRvciI6MSwiY29kX3VuaWRhZGUiOjg5LCJjcGYiOiIxMzEyODI1MDczMSIsImlkX3NldG9yIjo1MjQsIm5vbV9jZ20iOiJJc2FxdWUgTmV2ZXMgU2FudCdhbmEiLCJudW1jZ20iOjE0MDA1MCwidXNlcm5hbWUiOiJpc2FxdWUuc2FudGFuYSJ9LCJleHAiOjE2OTcwNjQ2MjUsImlhdCI6MTY5NzAzMjIyNSwiaXNzIjoibmV3c2FsaS5yaW9kYXNvc3RyYXMucmouZ292LmJyIiwibmJmIjoxNjk3MDMyMjI1fQ.wUxQI1alM0A3638c1Yx01Y3NgTttaK_3zrnYcVVZvuw,]39:10:User-Agent,21:PostmanRuntime/7.33.0,]15:6:Accept,3:*/*,]57:13:Postman-Token,36:4ef7fd28-f0a2-416a-a320-a6cfaa19d768,]25:4:Host,14:localhost:3350,]40:15:Accept-Encoding,17:gzip, deflate, br,]28:10:Connection,10:keep-alive,]]12:http_version;8:HTTP/1.1,}6:backup;0:~17:timestamp_created;18:1697032302.8675468^7:comment;0:;8:metadata;0:}6:marked;0:;9:is_replay;0:~11:intercepted;5:false!11:server_conn;469:3:via;0:~19:timestamp_tcp_setup;16:1697032225.55111^7:address;19:9:localhost;4:3350#]19:timestamp_tls_setup;0:~13:timestamp_end;17:1697032478.893024^15:timestamp_start;18:1697032225.5461097^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:baac6dca-5915-47e3-a56f-476efb33582a;8:sockname;22:3:::1;5:22274#1:0#1:0#]8:peername;21:3:::1;4:3350#1:0#1:0#]}11:client_conn;422:10:proxy_mode;7:regular;8:mitmcert;0:~19:timestamp_tls_setup;0:~13:timestamp_end;18:1697033078.8951516^15:timestamp_start;17:1697032225.540111^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:bbe98b4a-9ed6-4457-9fd3-e94cca252722;8:sockname;21:3:::1;4:8080#1:0#1:0#]8:peername;22:3:::1;5:22273#1:0#1:0#]}5:error;0:~2:id;36:4f315173-0f66-409f-94d5-47f027db1c4b;4:type;4:http;7:version;2:20#}7245:9:websocket;0:~8:response;5016:6:reason;2:OK,11:status_code;3:200#13:timestamp_end;18:1697033236.1156993^15:timestamp_start;18:1697033236.1140969^8:trailers;0:~7:content;4450:{"totalRecords":9,"error":"","items":[{"processo":"8/2004","data_andamento":"2019-03-22T00:00:00.000Z","nome_cgm_andamento":"Administrador","nome_setor_destino":"SEMAD/SUBGEP - Subsecretaria Municipal de Gestão de Pessoas","data_recebimento":"2019-03-22T00:00:00.000Z","nome_cgm_recebimento":"Administrador","cod_andamento":9,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":88,"cod_departamento":1,"cod_setor":1,"ano_exercicio_setor":"2003","cod_usuario":0,"timestamp":"2019-03-22T00:00:00.000Z","despachos":[]},{"processo":"8/2004","data_andamento":"2013-01-02T00:00:00.000Z","nome_cgm_andamento":"Administrador","nome_setor_destino":"Subsec.Mun.Gestão Pessoas e Segurança no Amb.Trabalho","data_recebimento":"2013-01-02T00:00:00.000Z","nome_cgm_recebimento":"Administrador","cod_andamento":8,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":58,"cod_departamento":1,"cod_setor":1,"ano_exercicio_setor":"2003","cod_usuario":0,"timestamp":"2013-01-02T00:00:00.000Z","despachos":[]},{"processo":"8/2004","data_andamento":"2012-03-23T07:00:00.000Z","nome_cgm_andamento":"Administrador","nome_setor_destino":"SEMGEP - Secretaria Municipal de Gestão de Pessoas","data_recebimento":"2012-03-23T07:00:00.000Z","nome_cgm_recebimento":"Administrador","cod_andamento":7,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":27,"cod_departamento":1,"cod_setor":1,"ano_exercicio_setor":"2003","cod_usuario":0,"timestamp":"2012-03-23T07:00:00.000Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-02-03T14:34:37.465Z","nome_cgm_andamento":"DICOP - SEMAD","nome_setor_destino":"DERHU - Depto. de Recursos Humanos","data_recebimento":"2004-02-03T14:47:59.131Z","nome_cgm_recebimento":"CARLOS OTÁVIO FERNANDES TAVARES","cod_andamento":6,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":2,"cod_setor":4,"ano_exercicio_setor":"2003","cod_usuario":1722,"timestamp":"2004-02-03T14:34:37.465Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-01-28T10:53:48.760Z","nome_cgm_andamento":"CARLOS OTÁVIO FERNANDES TAVARES","nome_setor_destino":"DICOP - Div. de Controle de Pessoal","data_recebimento":"2004-02-03T14:06:55.356Z","nome_cgm_recebimento":"DICOP - SEMAD","cod_andamento":5,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":2,"cod_setor":3,"ano_exercicio_setor":"2003","cod_usuario":1766,"timestamp":"2004-01-28T10:53:48.760Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-01-13T16:34:14.302Z","nome_cgm_andamento":"ROSILEA AGUIAR VON RANDOW","nome_setor_destino":"DERHU - Depto. de Recursos Humanos","data_recebimento":"2004-01-16T11:20:59.936Z","nome_cgm_recebimento":"NELITO SENRA ESTERQUE","cod_andamento":4,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":2,"cod_setor":4,"ano_exercicio_setor":"2003","cod_usuario":1395,"timestamp":"2004-01-13T16:34:14.302Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-01-13T10:48:03.576Z","nome_cgm_andamento":"NELITO SENRA ESTERQUE","nome_setor_destino":"SEMAD - Secretaria Municipal de Administração","data_recebimento":"2004-01-13T15:40:58.892Z","nome_cgm_recebimento":"ROSILEA AGUIAR VON RANDOW","cod_andamento":3,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":1,"cod_setor":1,"ano_exercicio_setor":"2003","cod_usuario":1363,"timestamp":"2004-01-13T10:48:03.576Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-01-06T13:30:00.000Z","nome_cgm_andamento":"SEMAD","nome_setor_destino":"DERHU - Depto. de Recursos Humanos","data_recebimento":"2004-01-13T10:25:57.410Z","nome_cgm_recebimento":"NELITO SENRA ESTERQUE","cod_andamento":2,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":2,"cod_setor":4,"ano_exercicio_setor":"2003","cod_usuario":327,"timestamp":"2004-01-06T13:30:00.000Z","despachos":[]},{"processo":"8/2004","data_andamento":"2004-01-05T10:27:24.229Z","nome_cgm_andamento":"DENIZE MOREIRA DE AZEVEDO BERTIN","nome_setor_destino":"SEMAD - Secretaria Municipal de Administração","data_recebimento":"2004-01-06T10:40:00.000Z","nome_cgm_recebimento":"SEMAD","cod_andamento":1,"cod_processo":8,"ano_exercicio":"2004","cod_orgao":2,"cod_unidade":5,"cod_departamento":1,"cod_setor":1,"ano_exercicio_setor":"2003","cod_usuario":161,"timestamp":"2004-01-05T10:27:24.229Z","despachos":[]}]},7:headers;379:21:13:total-records,1:9,]40:4:date,29:Wed, 11 Oct 2023 14:07:16 GMT,]35:27:access-control-allow-origin,1:*,]31:17:transfer-encoding,7:chunked,]37:29:access-control-expose-headers,1:*,]33:15:x-frame-options,10:SAMEORIGIN,]51:12:content-type,31:application/json; charset=utf-8,]37:16:x-xss-protection,13:1; mode=block,]36:22:x-content-type-options,7:nosniff,]18:6:server,6:Angel3,]]12:http_version;8:HTTP/1.1,}7:request;1068:4:path;45:/api/v1/protocolo/processos/andamentos/2004/8,9:authority;0:,6:scheme;4:http,6:method;3:GET,4:port;4:3350#4:host;9:localhost;13:timestamp_end;18:1697033235.8782544^15:timestamp_start;17:1697033235.877251^8:trailers;0:~7:content;0:,7:headers;785:552:13:Authorization,530:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImFub19leGVyY2ljaW8iOiIyMDIzIiwiYW5vX2V4ZXJjaWNpb19zZXRvciI6IjIwMDMiLCJjb2RfZGVwYXJ0YW1lbnRvIjoyLCJjb2Rfb3JnYW8iOjIsImNvZF9zZXRvciI6MSwiY29kX3VuaWRhZGUiOjg5LCJjcGYiOiIxMzEyODI1MDczMSIsImlkX3NldG9yIjo1MjQsIm5vbV9jZ20iOiJJc2FxdWUgTmV2ZXMgU2FudCdhbmEiLCJudW1jZ20iOjE0MDA1MCwidXNlcm5hbWUiOiJpc2FxdWUuc2FudGFuYSJ9LCJleHAiOjE2OTcwNjQ2MjUsImlhdCI6MTY5NzAzMjIyNSwiaXNzIjoibmV3c2FsaS5yaW9kYXNvc3RyYXMucmouZ292LmJyIiwibmJmIjoxNjk3MDMyMjI1fQ.wUxQI1alM0A3638c1Yx01Y3NgTttaK_3zrnYcVVZvuw,]39:10:User-Agent,21:PostmanRuntime/7.33.0,]15:6:Accept,3:*/*,]57:13:Postman-Token,36:d8c5aa10-aa89-4ddb-850f-71c5a83de450,]25:4:Host,14:localhost:3350,]40:15:Accept-Encoding,17:gzip, deflate, br,]28:10:Connection,10:keep-alive,]]12:http_version;8:HTTP/1.1,}6:backup;0:~17:timestamp_created;18:1697033235.8782544^7:comment;0:;8:metadata;0:}6:marked;0:;9:is_replay;0:~11:intercepted;5:false!11:server_conn;452:3:via;0:~19:timestamp_tcp_setup;17:1697033235.881254^7:address;19:9:localhost;4:3350#]19:timestamp_tls_setup;0:~13:timestamp_end;0:~15:timestamp_start;18:1697033235.8802545^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:fd206318-8a05-4393-8f84-888e73c41f85;8:sockname;22:3:::1;5:22820#1:0#1:0#]8:peername;21:3:::1;4:3350#1:0#1:0#]}11:client_conn;404:10:proxy_mode;7:regular;8:mitmcert;0:~19:timestamp_tls_setup;0:~13:timestamp_end;0:~15:timestamp_start;18:1697033235.8762827^3:sni;0:~11:tls_version;0:~11:cipher_list;0:]6:cipher;0:~11:alpn_offers;0:]4:alpn;0:~16:certificate_list;0:]3:tls;5:false!5:error;0:~18:transport_protocol;3:tcp;2:id;36:20cead20-c90c-4be7-8e5c-360a3bc8d8b4;8:sockname;21:3:::1;4:8080#1:0#1:0#]8:peername;22:3:::1;5:22819#1:0#1:0#]}5:error;0:~2:id;36:84ab3d64-c2e0-419e-837d-8116a73a6044;4:type;4:http;7:version;2:20#}

'str' object does not support item assignment in mitmproxy2swagger.py

└─$ pip install --no-cache-dir mitmproxy2swagger
Successfully installed mitmproxy2swagger-0.8.0
└─$ mitmproxy2swagger -i Downloads/flows -o spec.yml -p http://google.com/
Traceback (most recent call last):
File "/home/krish500/.local/bin/mitmproxy2swagger", line 8, in
sys.exit(main())
^^^^^^
File "/home/krish500/.local/lib/python3.11/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 98, in main
swagger['servers'] = []

TypeError: 'str' object does not support item assignment
└─$ uname -a
Linux DESKTOP-18BPFD5 5.15.79.1-microsoft-standard-WSL2 https://github.com/alufers/mitmproxy2swagger/pull/1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 GNU/Linux
$ mitmweb --version
Mitmproxy: 9.0.1
Python: 3.11.1
OpenSSL: OpenSSL 3.0.7 1 Nov 2022
Platform: Linux-5.15.79.1-microsoft-standard-WSL2-x86_64-with-glibc2.36
─$ python3 --version
Python 3.11.1

RuntimeError: Cannot change server.via on open connection.

Hey, this looks really useful. Gave it a go but got this error.

mitmproxy2swagger -i ~/Downloads/flows  -o test-api -p test-api
No existing swagger file found. Creating new one.
Traceback (most recent call last):
  File "/usr/local/bin/mitmproxy2swagger", line 8, in <module>
    sys.exit(main())
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 111, in main
    for f in freader.stream():
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/io/io.py", line 48, in stream
    yield FLOW_TYPES[mdata["type"]].from_state(mdata)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/flow.py", line 165, in from_state
    f.set_state(state)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/flow.py", line 160, in set_state
    super().set_state(state)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/stateobject.py", line 47, in set_state
    setattr(self, attr, make_object(cls, val))
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/stateobject.py", line 94, in make_object
    return _process(typeinfo, val, True)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/stateobject.py", line 56, in _process
    return typeinfo.from_state(val)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/connection.py", line 331, in from_state
    server.set_state(state)
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/connection.py", line 353, in set_state
    self.via = state["via2"]
  File "/home/stuart/.local/lib/python3.10/site-packages/mitmproxy/connection.py", line 299, in __setattr__
    raise RuntimeError(f"Cannot change server.{name} on open connection.")
RuntimeError: Cannot change server.via on open connection.

flows.zip

mitmweb --mode upstream:http://172.18.0.2

Broken Imports

I don't understand what is going on in the error message below.
Also I cannot call mitmproxy2swagger from the command line after installing it with pip3 install mitmproxy2swagger
I have to forcefully call it from the full filepath with python3

bumping #153

$ python3 ~/Library/Python/3.9/lib/python/site-packages/mitmproxy2swagger/mitmproxy2swagger.py -i ~/Documents/TMS-login\ flows -o ~/Documents/tms_trials
Traceback (most recent call last):
  File "/Users/USER/Library/Python/3.9/lib/python/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 16, in <module>
    from mitmproxy2swagger import console_util, swagger_util
  File "/Users/USER/Library/Python/3.9/lib/python/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 16, in <module>
    from mitmproxy2swagger import console_util, swagger_util
ImportError: cannot import name 'console_util' from partially initialized module 'mitmproxy2swagger' (most likely due to a circular import) (/Users/USER/Library/Python/3.9/lib/python/site-packages/mitmproxy2swagger/mitmproxy2swagger.py)

No existing swagger file found. Creating new one.

Full error log.

Traceback (most recent call last):
  File "/home/[username]/.local/bin/mitmproxy2swagger", line 8, in <module>
    sys.exit(main())
  File "/home/[username]/.local/lib/python3.10/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 178, in main
    for req in capture_reader.captured_requests():
  File "/home/[username]/.local/lib/python3.10/site-packages/mitmproxy2swagger/har_capture_reader.py", line 117, in captured_requests
    for entry in data["log"]["entries"].persistent():
TypeError: 'int' object is not subscriptable  

Reproduce

mitmproxy2swagger -i flows -o spec.yml -p https://goo.gle/api/v1

TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'NoneType'

Just installed mitmproxy2swagger by running: pip3 install mitmproxy2swagger

Post successful installation, when I run mitmproxy2swagger -h, I get an error message as such

Traceback (most recent call last):
  File "[REDACTED]/bin/mitmproxy2swagger", line 5, in <module>
    from mitmproxy2swagger.mitmproxy2swagger import main
  File "[REDACTED]/lib/python3.9/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 66, in <module>
    def main(override_args: Sequence[str] | None = None):
TypeError: unsupported operand type(s) for |: '_GenericAlias' and 'NoneType'

Not sure why this error is rising up.

'str' object does not support item assignment in mitmproxy2swagger.py

└─$ pip install --no-cache-dir mitmproxy2swagger
Successfully installed mitmproxy2swagger-0.8.0
└─$ mitmproxy2swagger -i Downloads/flows -o spec.yml -p http://google.com
Traceback (most recent call last):
File "/home/krish500/.local/bin/mitmproxy2swagger", line 8, in
sys.exit(main())
^^^^^^
File "/home/krish500/.local/lib/python3.11/site-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 98, in main
swagger['servers'] = []
~~~~~~~^^^^^^^^^^^
TypeError: 'str' object does not support item assignment
└─$ uname -a
Linux DESKTOP-18BPFD5 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022 x86_64 GNU/Linux
$ mitmweb --version
Mitmproxy: 9.0.1
Python: 3.11.1
OpenSSL: OpenSSL 3.0.7 1 Nov 2022
Platform: Linux-5.15.79.1-microsoft-standard-WSL2-x86_64-with-glibc2.36
─$ python3 --version
Python 3.11.1

Flow file corrupted: mitmproxy 9.0.1 cannot read files with flow format version 20, please update mitmproxy.

Hello,

using the latest versions of mitmproxy and mitmproxy2swagger I'm experience the following error.

Flow file corrupted: mitmproxy 9.0.1 cannot read files with flow format version 20, please update mitmproxy.
Done!

The flow file contains just a request (with associated response).

This is the command I'm executing:

mitmproxy2swagger -i flows -o out -p https://base_url/

Any hint on how to fix it?

Thanks,
Lorenzo

Tag releases

hi!

I'm interested in packaging mitmproxy2swagger for Arch Linux, any chance you could create a 0.1.0 tag+release on github? :) Just a tag is sufficient, but releases would also show up in my github notifications inbox.

Thanks!

Error thrown at generating spec

When I'm trying to run the command for generating spec.yml I get an exception

File "/usr/local/bin/mitmproxy2swagger", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/mitmproxy2swagger/mitmproxy2swagger.py", line 127, in main
path = strip_query_string(url).removeprefix(args.api_prefix)
AttributeError: 'str' object has no attribute 'removeprefix'

I've tried it with multiple targets and I certainly do have the endpoints exported that could be processed so my guess is there's something wrong with mitmproxy2swagger itself but I can't seem to find out what it is. Anyone has had similar problems?

Consider name change to mitmproxy2openapi

I suspect you're disinclined to rename the project, as there's likely quite a bit invested in the current project name, but I thought I'd alert you to some comments that came up when I tried to add this project to a directory of OpenAPI tools:

apisyouwonthate/openapi.tools#400

Thanks for maintaining the project, I've found it very useful for documenting existing APIs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.