我在 Python 中调用亚马逊产品广告 API 来获取某些产品的数据:https ://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html 。
我通过以下方式导入 API:
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
我使用以下方法调用 API:
response = default_api.search_items(search_items_request)
然后我尝试使用基本代码将响应对象写入文件:
with open('paapi_response.json', 'w') as outfile:
outfile.write(response)
但我收到以下错误:
TypeError : write() 参数必须是 str,而不是 SearchItemsResponse
我不想将其转换为字符串,因为我想保留文件的确切响应。有没有办法将响应对象原样打印到文件中?