Skip to content

[Bug]: OpenAPI generated Client for Python not accepting API responses #198

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

Closed
1 task done
Willmish opened this issue Nov 23, 2022 · 0 comments · Fixed by #305
Closed
1 task done

[Bug]: OpenAPI generated Client for Python not accepting API responses #198

Willmish opened this issue Nov 23, 2022 · 0 comments · Fixed by #305
Labels
bug Something isn't working

Comments

@Willmish
Copy link
Collaborator

Contact Details

GitHub/Slack: Willmish

What happened?

On the newest version, the generated Python OpenAPI client for the API does not accept the type of the returned data. (Even when accept_content_types parameter is specified). When not specified and only query parameters are specified, it still fails there. (Most likely the accept_content_types parameter is not being handled properly)

Python version : 3.8
Code ran:

import openapi_client
from pprint import pprint
from openapi_client.apis.tags import carbon_aware_api
from openapi_client.model.emissions_data import EmissionsData
from  dateutil.parser import parse

configuration = openapi_client.Configuration(
        host = "https://carbon-aware-api.azurewebsites.net"
)

# Enter a context with an instance of the API client
api_client =  openapi_client.ApiClient(configuration)
# Create an instance of the API class
api_instance = carbon_aware_api.CarbonAwareApi(api_client)

query_params = {
        'location': "westcentralus",
        'time': parse('2022-08-15T20:55'),
    }
try:
    #api_response = api_instance.get_emissions_data_for_location_by_time(location=location, time=start_time, to_time=to_time, duration_minutes=duration_minutes)
    api_response = api_instance.get_emissions_data_for_location_by_time(query_params = query_params, accept_content_types=('application/json; charset=utf-8',))

    pprint(api_response)
except openapi_client.ApiException as e:
    print("Exception when calling CarbonAwareApi->emissions_bylocation_get: %s\n" % e)

client

WebAPI (Default)

Relevant log output

ApiValueError                             Traceback (most recent call last)
Cell In [9], line 22
     16 query_params = {
     17         'location': "westcentralus",
     18         'time': parse('2022-08-15T20:55'),
     19     }
     20 try:
     21     #api_response = api_instance.get_emissions_data_for_location_by_time(location=location, time=start_time, to_time=to_time, duration_minutes=duration_minutes)
---> 22     api_response = api_instance.get_emissions_data_for_location_by_time(query_params = query_params, accept_content_types=('application/json; charset=utf-8',))
     24     pprint(api_response)
     25 except openapi_client.ApiException as e:

File /opt/homebrew/Caskroom/miniconda/base/envs/sdktest2/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/paths/emissions_bylocation/get.py:312, in GetEmissionsDataForLocationByTime.get_emissions_data_for_location_by_time(self, query_params, accept_content_types, stream, timeout, skip_deserialization)
    304 def get_emissions_data_for_location_by_time(
    305     self,
    306     query_params: RequestQueryParams = frozendict.frozendict(),
   (...)
    310     skip_deserialization: bool = False,
    311 ):
--> 312     return self._get_emissions_data_for_location_by_time_oapg(
    313         query_params=query_params,
    314         accept_content_types=accept_content_types,
    315         stream=stream,
    316         timeout=timeout,
    317         skip_deserialization=skip_deserialization
    318     )

File /opt/homebrew/Caskroom/miniconda/base/envs/sdktest2/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/paths/emissions_bylocation/get.py:250, in BaseApi._get_emissions_data_for_location_by_time_oapg(self, query_params, accept_content_types, stream, timeout, skip_deserialization)
    248 response_for_status = _status_code_to_response.get(str(response.status))
    249 if response_for_status:
--> 250     api_response = response_for_status.deserialize(response, self.api_client.configuration)
    251 else:
    252     api_response = api_client.ApiResponseWithoutDeserialization(response=response)

File /opt/homebrew/Caskroom/miniconda/base/envs/sdktest2/lib/python3.8/site-packages/openapi_client-1.0.0-py3.8.egg/openapi_client/api_client.py:929, in OpenApiResponse.deserialize(self, response, configuration)
    927 if self.content is not None:
    928     if content_type not in self.content:
--> 929         raise ApiValueError(
    930             f"Invalid content_type returned. Content_type='{content_type}' was returned "
    931             f"when only {str(set(self.content))} are defined for status_code={str(response.status)}"
    932         )
    933     body_schema = self.content[content_type].schema
    934     if body_schema is None:
    935         # some specs do not define response content media type schemas

ApiValueError: Invalid content_type returned. Content_type='application/json; charset=utf-8' was returned when only {'application/json'} are defined for status_code=200

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Willmish Willmish added the bug Something isn't working label Nov 23, 2022
Willmish added a commit to Willmish/carbon-aware-sdk that referenced this issue Jan 18, 2023
…otations.

* Issue reference: Green-Software-Foundation#198
* Produces filters now accept application/json; charset=utf-8

Signed-off-by: Szymon Duchniewicz <[email protected]>
@Willmish Willmish linked a pull request Jan 23, 2023 that will close this issue
6 tasks
Willmish added a commit to Willmish/carbon-aware-sdk that referenced this issue Feb 25, 2023
…otations.

* Issue reference: Green-Software-Foundation#198
* Produces filters now accept application/json; charset=utf-8

Signed-off-by: Szymon Duchniewicz <[email protected]>
Willmish added a commit to Willmish/carbon-aware-sdk that referenced this issue Feb 26, 2023
…otations.

* Issue reference: Green-Software-Foundation#198
* Produces filters now accept application/json; charset=utf-8

Signed-off-by: Szymon Duchniewicz <[email protected]>
helayoty pushed a commit to helayoty/carbon-aware-sdk that referenced this issue Jun 16, 2023
…otations.

* Issue reference: Green-Software-Foundation#198
* Produces filters now accept application/json; charset=utf-8

Signed-off-by: Szymon Duchniewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant