Comments (2)
This is because the code is written for a deprecated API.
You have two choices in order to make this to work.
- Modify the
reddit.py
script. You need to change a couple of function name and add a client_id and a client_secret. This two tokens are generated in the reddit app page (https://github.com/reddit-archive/reddit/wiki/OAuth2). This is the one I used. - This solutions it's the easiest one. You can copy the
reddit.py
script from another folder of the repo, because that problem i'ts already fixed. I notice this when I advance the book.
Hope it helps!
PD: I attach the script I used.
reddit.py.txt
from practical-docker-with-python.
#file reddit.py
#make app on reddit first to get keys
import praw
from states import log
#https://www.reddit.com/wiki/api
#https://www.reddit.com/prefs/apps
#https://stackoverflow.com/questions/39521621/raise-clientexceptionrequired-message-formatattribute-praw-exceptions-client
def get_latest_news(sub_reddits):
log.debug('Fetching news from reddit')
#r = praw.Reddit(user_agent='Practical Docker With Python tutorial')
r = praw.Reddit(
username="user_name_on_reddit",
password="password_on_rediit",
client_id="see stackoverflow at the beginning",
client_secret="see stackoverflow at the beginning",
user_agent="Karma breakdown 1.0 by /u/zoldaten_",
redirect_uri='http://127.0.0.1:65010/',
)
sub_reddits = clean_up_subreddits(sub_reddits)
log.debug(f"Fetching subreddits: {sub_reddits}")
submissions = r.subreddit(sub_reddits).top(limit=5)
submission_content = ''
try:
for post in submissions:
submission_content += f"{post.title} - {post.url} \n\n"
except praw.errors.Forbidden:
log.info(f"subreddit {sub_reddits} is private".format())
submission_content = "Sorry couldn't fetch; subreddit is private"
except praw.errors.InvalidSubreddit:
log.info(f"Subreddit {sub_reddits} is invalid or doesn''t exist.")
submission_content = "Sorry couldn't fetch; subreddit doesn't seem to exist"
except praw.errors.NotFound :
log.info(f"Subreddit {sub_reddits} is invalid or doesn''t exist.")
submission_content = "Sorry couldn't fetch; something went wrong, please do send a report to @sathyabhat"
return submission_content
def clean_up_subreddits(sub_reddits):
log.debug('Got subreddits to clean: {0}'.format(sub_reddits))
return sub_reddits.strip().replace(" ", "").replace(',', '+')
from practical-docker-with-python.
Related Issues (11)
- No Output HOT 4
- Alpine doesn't reinstall cached files, it can't install pandas HOT 1
- missing documentation in the book HOT 1
- where is requirements.txt and newsbot.py on chapter3? HOT 1
- Add missing Key in the json_response dictionary HOT 2
- Getting exception while running chapter-3 module HOT 1
- Chapter 5 excercise 2 error HOT 2
- Exercise 2 of chapter 5 HOT 10
- exercise 1 of chapter 6 HOT 2
- AttributeError: 'Reddit' object has no attribute 'get_subreddit' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from practical-docker-with-python.