I have the following Python program to create strawpolls using strawpoll.me's API as described here.
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())
This used to work, but it isn't any more. I'm wondering what changed. Here's what I get now:
<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: '
>>>
If I send the same parameters to the endpoint in a terminal like this:
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
I get the expected response.