prance
prance copied to clipboard
Prance doesn't work with python 3.12.1
Expected Behaviour
Spec should get validated for valid swagger file.
Minimal Example Spec
- http://petstore.swagger.io/v2/swagger.json
Actual Behaviour
Raises AttributeError: '_io.BufferedReader' object has no attribute 'decode'
Steps to Reproduce
- Execute below command:
$ prance validate http://petstore.swagger.io/v2/swagger.json
Processing "http://petstore.swagger.io/v2/swagger.json"...
-> Resolving external references.
Traceback (most recent call last):
File "/Users/apple/.pyenv/versions/3.12.1/bin/prance", line 8, in <module>
sys.exit(cli())
^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/cli.py", line 114, in command_invoke
original_invoke(ctx)
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/cli.py", line 209, in validate
__validate(parser, name)
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/cli.py", line 65, in __validate
parser.parse()
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/__init__.py", line 148, in parse
self._validate()
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/__init__.py", line 316, in _validate
BaseParser._validate(self)
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/__init__.py", line 187, in _validate
validator(parsed)
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/prance/__init__.py", line 248, in _validate_openapi_spec_validator
validate_spec(self.specification)
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/shortcuts.py", line 17, in validate_spec
return validator.validate(spec, spec_url=spec_url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/validation/proxies.py", line 27, in validate
for err in validator.iter_errors(instance, spec_url=spec_url):
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/validation/decorators.py", line 22, in wrapper
for err in errors:
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/validation/validators.py", line 89, in iter_errors
yield from self.schema_validator.iter_errors(instance)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<attrs generated init jsonschema.validators.create.<locals>.Validator>", line 5, in __init__
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema/validators.py", line 216, in __attrs_post_init__
self.resolver = RefResolver.from_schema(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema/validators.py", line 772, in from_schema
return cls(base_uri=id_of(schema), referrer=schema, *args, **kwargs) # noqa: B026, E501
^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema/_legacy_validators.py", line 12, in id_of
if schema is True or schema is False or "$ref" in schema:
^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/schemas/utils.py", line 28, in get_schema_content
content, _ = get_schema(version)
^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/openapi_spec_validator/schemas/utils.py", line 24, in get_schema
return FilePathReader(schema_path_full).read()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema_spec/readers.py", line 37, in read
return all_urls_handler(uri), uri
^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema_spec/handlers/file.py", line 45, in __call__
return self._open(uri)
^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema_spec/handlers/urllib.py", line 18, in _open
return super().__call__(fh)
^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/site-packages/jsonschema_spec/handlers/file.py", line 41, in __call__
parsed_url = urlparse(uri)
^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/urllib/parse.py", line 394, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/urllib/parse.py", line 133, in _coerce_args
return _decode_args(args) + (_encode_result,)
^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/urllib/parse.py", line 117, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/urllib/parse.py", line 117, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
^^^^^^^^
File "/Users/apple/.pyenv/versions/3.12.1/lib/python3.12/tempfile.py", line 494, in __getattr__
a = getattr(file, name)
^^^^^^^^^^^^^^^^^^^
AttributeError: '_io.BufferedReader' object has no attribute 'decode'
Environment
- OS: MacOS
- Python version: 3.12.1
- Swagger/OpenAPI version used: 2.0 (http://petstore.swagger.io/v2/swagger.json)
- Backend: (flex, swagger-spec-validator or openapi-spec-validator)