benjhar / JokeAPI-Python

An API Wrapper for Sv443's JokeAPI
GNU General Public License v3.0
33 stars 9 forks source link

get_joke() Example #12

Closed tech-savvy-guy closed 3 years ago

tech-savvy-guy commented 3 years ago

Hi. I was trying to use the Python wrapper of Joke API. I was going through the README.md when I came across this get_joke() example:

from jokeapi import Jokes # Import the Jokes class
import asyncio

async def print_joke():
    j = await Jokes()  # Initialise the class
    await j.get_joke()  # Retrieve a random joke
    if joke["type"] == "single": # Print the joke
        print(joke["joke"])
    else:
        print(joke["setup"])
        print(joke["delivery"])

asyncio.run(print_joke())

Bugs:

To Reproduce

  1. Just copy the example under the README.md and run it.
  2. See error

Expected behavior

I expected the function to return a joke after each call.

benjhar commented 3 years ago

It seems that this is a Windows only issue that I wasn't aware of as I don't have a Windows machine. Please try prepending the following snippet to the code.

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Will fix the documentation mistake when I get the chance.

tech-savvy-guy commented 3 years ago

Alright, thanks for the update.