python - Tkinter Reddit scraper (Tkinter and Praw) returns error "TypeError" -


im relatively new python , trying create tkinter application collects information specific subreddit , returns user in tkinter window. however, when run code returns error:

typeerror: 'nonetype' object has no attribute 'getitem'

there appears nothing else on web can fix this, therefore believe it's appropriate asked here.

my apologies if there many other problems code here, remember, new coding.

thanks, -jeff

try: tkinter import * except importerror: tkinter import * webbrowser import open datetime import date import praw  """ scraper (eventually able to) search user-defined subreddit , return top ten posts subreddit" """  class redditscraper(frame):      def makewidgets(self):         intro = "reddit client"          label(self, text="what subreddit wish view?").pack()         self.e = entry(self)         self.e.pack(padx=5)          b = button(self, text="search subreddit", command=self.search)         b.pack(pady=5)       def search(self):         user_agent = "reddit client (of sort), (/u/cowinafridge)"         r = praw.reddit(user_agent=user_agent)         posts = r.get_subreddit(self.e.get()).get_hot(limit = 10)         self.makewidgets.distroy         return posts      def actualframe(self):            self.newframe = labelframe(self)         self.newframe.pack(fill="both", expand="yes", anchor = nw)         posts = self.search()         row = 0         p in posts:             gotoarticle = partial(open, p.url)             title = "(" + str(p.score) + ") " + p.title             label(self.newframe, text= title, pady= 10, wraplength= 700, justify= left).grid(row= row, column= 0, sticky= w)             button(self.newframe, text= "read more!", command= gotoarticle).grid(row= row+1, column= 0, sticky= w)             row = row + 2      def __init__(self, master):           frame.__init__(self, master)                 self.makewidgets()         self.actualframe()         self.pack()      root = tk()     app = redditscraper(root)     app.master.title("reddit client v.1.0")     app.mainloop()     root.distroy 

the error gets outputted follows:

traceback (most recent call last):   file "myredditscraper.py", line 53, in <module>     app = redditscraper(root)   file "myredditscraper.py", line 49, in __init__     self.actualframe()   file "myredditscraper.py", line 37, in actualframe     posts = self.search()   file "myredditscraper.py", line 29, in search     posts = r.get_subreddit(self.e.get()).get_hot(limit = 10)   file "/library/python/2.7/site-packages/praw/__init__.py", line 1018, in get_subreddit     return objects.subreddit(self, subreddit_name, *args, **kwargs)   file "/library/python/2.7/site-packages/praw/objects.py", line 1356, in __init__     subreddit_name = json_dict['url'].split('/')[2] typeerror: 'nonetype' object has no attribute '__getitem__' 

i think issue here you're attempting value in entry self.e before call app.mainloop().

in self.actualframe() call self.search(), makes call:

posts = r.get_subreddit(self.e.get()).get_hot(limit = 10) 

before attempt call self.e.get() must start mainloop of gui.

i'm not clear on structure of code, if trying retrieve value self.e, wait call self.search() until after call app.mainloop()


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -