I am calling the Amazon Product Advertising API in Python to get data for certain products: https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html.
I import the API with:
from paapi5_python_sdk.api.default_api import DefaultApi
from paapi5_python_sdk.models.search_items_request import SearchItemsRequest
from paapi5_python_sdk.models.search_items_resource import SearchItemsResource
I call the API using this:
response = default_api.search_items(search_items_request)
Then I try to write the response object to a file using basic code:
with open('paapi_response.json', 'w') as outfile:
outfile.write(response)
But I get the following error:
TypeError : write() argument must be str, not SearchItemsResponse
I don't want to convert it to string because I want to keep the exact response of the file. Is there any way to print the response object to a file just as it is?