我有以下Python程序,如here.所述,使用strawpoll.me的API创建秸秆投票>
import aiohttp import asyncio async def createPoll(): question = "Is this thing on?" options = ["Yes", "No", "Maybe"] try: async with aiohttp.ClientSession() as session: async with session.post( "https://www.strawpoll.me/api/v2/polls", json={ "title": question, "options": options, "multi": "false" }, headers={"Content Type": "application/json"} ) as response: print(response) json = await response.json() strawpoll_id = json["id"] print(f"https://strawpoll.me/{strawpoll_id}") except Exception as e: print(e) if __name__ == '__main__': asyncio.run(createPoll())
这曾经有用,但现在不行了。我想知道发生了什么变化。这是我现在得到的:
<ClientResponse(https://www.strawpoll.me/api/v2/polls) [400 Bad Request]> <CIMultiDictProxy('Connection': 'close', 'Content-Length': '0')> 0, message='Attempt to decode JSON with unexpected mimetype: ' >>>
如果我将相同的参数发送到这样的终端中的端点:
curl -H "Content-Type: application/json" -X POST -d '{"title": "Is this this on?", "options": ["Yes", "No", "Maybe"], "multi": "false"}' https://www.strawpoll.me/api/v2/polls
我得到了预期的答复。
我有以下Python程序,如此处所述,使用strawpoll.me的API创建秸秆投票。导入aiohttp导入asyncio异步def createPoll():问题=“这东西在吗?” ...
我尝试过: