wy-z / requests-openapi

A lightweight but powerful and easy-to-use Python client library for OpenAPI v3.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module 'yaml' has no attribute 'CLoader'. Did you mean: 'Loader'?

fbordalo opened this issue · comments

commented

Python 3.11.1 (main, Feb 3 2023, 13:30:13) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import requests_openapi
requests_openapi.Client().load_spec_from_file("index.yaml")
Traceback (most recent call last):
File "", line 1, in
File "/home//.pyenv/versions/3.11.1/envs/pytest/lib/python3.11/site-packages/requests_openapi/core.py", line 272, in load_spec_from_file
spec = load_spec_from_file(file_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/
/.pyenv/versions/3.11.1/envs/pytest/lib/python3.11/site-packages/requests_openapi/core.py", line 132, in load_spec_from_file
return yaml.load(spec_str, Loader=yaml.CLoader)
^^^^^^^^^^^^
AttributeError: module 'yaml' has no attribute 'CLoader'. Did you mean: 'Loader'?

Glad to receive your feedback~
However, 'CLoader' should be an attribute of pyyaml, you can refer to the official documentation. https://github.com/yaml/pyyaml

>>> yaml.load(stream, Loader=yaml.CLoader)
>>> yaml.dump(data, Dumper=yaml.CDumper)

What's your pyyaml version? Could you try pip install -U pyyaml and then test it again?
@fbordalo

I've also looked through the official documentation and found that it's possible some platform distributions do not include libyaml.
I've recently released a new version to refine this issue, which you might want to try out. #9 1.0.3 pip install requests-openapi -U
It's advisable to use CLoader whenever possible, as it offers better performance, especially noticeable with larger openapi files.