0

I'm not very good with API and async whatnot but this piece of code is literally taken right from the asyncpraw documentation, yet it's producing an error. I'd appreciate it if anyone can help.

import asyncpraw reddit = asyncpraw.Reddit( client_id="CLIENT_ID", client_secret="CLIENT_SECRET", user_agent="USER_AGENT", ) print(reddit.read_only) subreddit = await reddit.subreddit("ProgrammerHumor") async for submission in subreddit.hot(limit=10): print(submission.title) 

It's supposed to print the top ten posts on reddit from r/programmerhumor

Error pic

Edit:

I changed line 10 to this:

async def getSubreddit(): return await reddit.subreddit("ProgrammerHumor") subreddit = getSubreddit() 

Got this

Error #2

5
  • Edit your post to quote the error message that you receive. Commented Dec 4, 2022 at 14:32
  • I'm using python v3.8 Commented Dec 4, 2022 at 14:56
  • I added the pic Commented Dec 4, 2022 at 14:57
  • Does this answer your question? Why can I only use the await keyword inside of async function? Commented Dec 4, 2022 at 15:28
  • It seems to be a solution, but I'm not sure how to integrate that into my program. I edited the above code to the best of my ability, but the result is about the same Commented Dec 4, 2022 at 15:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.