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

'_io.BufferedReader' object has no attribute 'decode' #209

Closed
spaceone opened this issue Jun 6, 2023 · 7 comments
Closed

'_io.BufferedReader' object has no attribute 'decode' #209

spaceone opened this issue Jun 6, 2023 · 7 comments

Comments

@spaceone
Copy link

spaceone commented Jun 6, 2023

I get the error message without an traceback when executing:

# python3 -m openapi_spec_validator openapi.json 
'_io.BufferedReader' object has no attribute 'decode'
# python3 --version
Python 3.7.3
Requirement already satisfied: openapi-spec-validator in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (0.5.6)
Requirement already satisfied: importlib-resources<6.0.0,>=5.8.0 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-spec-validator) (5.12.0)                                                                                
Requirement already satisfied: jsonschema<4.18.0,>=4.0.0 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-spec-validator) (4.17.3)                                                                                        
Requirement already satisfied: jsonschema-spec<0.2.0,>=0.1.1 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-spec-validator) (0.1.4)                                                                                     
Requirement already satisfied: lazy-object-proxy<2.0.0,>=1.7.1 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-spec-validator) (1.9.0)                                                                                   
Requirement already satisfied: openapi-schema-validator<0.5.0,>=0.4.2 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-spec-validator) (0.4.4)                                                                            
Requirement already satisfied: zipp>=3.1.0 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from importlib-resources<6.0.0,>=5.8.0->openapi-spec-validator) (3.15.0)                                                                   
Requirement already satisfied: attrs>=17.4.0 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema<4.18.0,>=4.0.0->openapi-spec-validator) (23.1.0)                                                                         
Requirement already satisfied: importlib-metadata in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema<4.18.0,>=4.0.0->openapi-spec-validator) (6.6.0)                                                                     
Requirement already satisfied: pkgutil-resolve-name>=1.3.10 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema<4.18.0,>=4.0.0->openapi-spec-validator) (1.3.10)                                                          
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema<4.18.0,>=4.0.0->openapi-spec-validator) (0.19.3)                                         
Requirement already satisfied: typing-extensions in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema<4.18.0,>=4.0.0->openapi-spec-validator) (4.6.3)                                                                      
Requirement already satisfied: PyYAML>=5.1 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema-spec<0.2.0,>=0.1.1->openapi-spec-validator) (6.0)                                                                          
Requirement already satisfied: pathable<0.5.0,>=0.4.1 in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from jsonschema-spec<0.2.0,>=0.1.1->openapi-spec-validator) (0.4.3)                                                             
Requirement already satisfied: rfc3339-validator in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from openapi-schema-validator<0.5.0,>=0.4.2->openapi-spec-validator) (0.1.4)                                                         
Requirement already satisfied: six in ./ucs-test-udm-rest-api/lib/python3.7/site-packages (from rfc3339-validator->openapi-schema-validator<0.5.0,>=0.4.2->openapi-spec-validator) (1.16.0) 
@spaceone
Copy link
Author

spaceone commented Jun 6, 2023

got the traceback with some debugging:

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/lib/python3.7/site-packages/openapi_spec_validator/__main__.py", line 102, in <module>
    main()
  File "/lib/python3.7/site-packages/openapi_spec_validator/__main__.py", line 73, in main
    spec, spec_url = reader(args_parsed.filename)
  File "/lib/python3.7/site-packages/openapi_spec_validator/readers.py", line 23, in read_from_filename
    return all_urls_handler(uri), uri
  File "/lib/python3.7/site-packages/jsonschema_spec/handlers/file.py", line 45, in __call__
    return self._open(uri)
  File "/lib/python3.7/site-packages/jsonschema_spec/handlers/urllib.py", line 18, in _open
    return super().__call__(fh)
  File "/lib/python3.7/site-packages/jsonschema_spec/handlers/file.py", line 41, in __call__
    parsed_url = urlparse(uri)
  File "/usr/lib/python3.7/urllib/parse.py", line 367, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "/usr/lib/python3.7/urllib/parse.py", line 123, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "/usr/lib/python3.7/urllib/parse.py", line 107, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "/usr/lib/python3.7/urllib/parse.py", line 107, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "/usr/lib/python3.7/tempfile.py", line 615, in __getattr__
    a = getattr(file, name)
AttributeError: '_io.BufferedReader' object has no attribute 'decode'

@spaceone
Copy link
Author

spaceone commented Jun 6, 2023

work with an old version: python3 -m pip install openapi-spec-validator==0.4.0 jsonschema-spec==0.1.4

@p1c2u
Copy link
Collaborator

p1c2u commented Jun 10, 2023

Hi @spaceone ,

I can;t reproduce it. Can you prepare minimal example to reproduce the issue?

@spaceone
Copy link
Author

Hi @spaceone ,

I can;t reproduce it. Can you prepare minimal example to reproduce the issue?

The exact code we execute is:
https://github.com/univention/univention-corporate-server/blob/87d92592015822ef25b3d052a6b7206295d0e462~/test/ucs-test/tests/73_udm-rest/01_openapi_validation

Our workaround is:
https://github.com/univention/univention-corporate-server/blob/87d92592015822ef25b3d052a6b7206295d0e462/test/ucs-test/tests/73_udm-rest/01_openapi_validation

The content of openapi.json is irrelevant, as that file is not yet used.

@p1c2u
Copy link
Collaborator

p1c2u commented Jun 10, 2023

p1c2u/jsonschema-path#14

Temporary workaround will be downgrading typing-extensions to version below 4.6:

pip install "typing-extensions<4.6"

@spaceone
Copy link
Author

wonderful, thanks!

@p1c2u p1c2u closed this as completed Jun 11, 2023
@ambadyanands
Copy link

ambadyanands commented Jun 17, 2024

p1c2u/jsonschema-path#14

Temporary workaround will be downgrading typing-extensions to version below 4.6:

pip install "typing-extensions<4.6"

Unfortuantely this breaks compatibility with pydantic now.

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pydantic-core 2.10.0 requires typing-extensions!=4.7.0,>=4.6.0, but you have typing-extensions 4.5.0 which is incompatible.
pydantic 2.4.0 requires typing-extensions>=4.6.1, but you have typing-extensions 4.5.0 which is incompatible.

Any idea about what would be a proper solution that will work with latest/recent version of the dependencies?

Here's the related issue for reference, if it helps:
https://gitlab.com/gnukhata/gkcore/-/issues/745

Edit:
I mixed up the issues on downgrading openapi-spec-validator with the issues on downgrading typing-extensions. The downgrade related issue regarding the latter is with pydantic. Updated the error message above to fix the same.

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

3 participants