我正在尝试学习 Python,同时学习 PRAW。我正在尝试从 PyCharm 运行以下内容并保留以下错误。下面的代码是基本的第一个教程。
import time
import praw
r = praw.Reddit('PRAW related-question monitor by u/_Daimon_ v 1.0.'
'Url: https://praw.readthedocs.org/en/latest/'
'pages/writing_a_bot.html')
r.login()
already_done = []
prawWords = ['praw', 'reddit_api', 'mellort']
while True:
subreddit = r.get_subreddit('learnpython')
for submission in subreddit.get_hot(limit=10):
op_text = submission.selftext.lower()
has_praw = any(string in op_text for string in prawWords)
# Test if it contains a PRAW-related question
if submission.id not in already_done and has_praw:
msg = '[PRAW related thread](%s)' % submission.short_link
r.send_message('_Daimon_', 'PRAW Thread', msg)
already_done.append(submission.id)
time.sleep(1800)
错误
C:\Python34\python.exe C:/Users/Administrator/PycharmProjects/untitled1/Reddit
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled1/Reddit", line 6, in <module>
r.login('rbevans', 'bowstead')
File "C:\Python34\lib\site-packages\praw\__init__.py", line 1266, in login
self.user = self.get_redditor(user)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 890, in get_redditor
return objects.Redditor(self, user_name, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\objects.py", line 663, in __init__
fetch, info_url)
File "C:\Python34\lib\site-packages\praw\objects.py", line 72, in __init__
self.has_fetched = self._populate(json_dict, fetch)
File "C:\Python34\lib\site-packages\praw\objects.py", line 127, in _populate
json_dict = self._get_json_dict() if fetch else {}
File "C:\Python34\lib\site-packages\praw\objects.py", line 120, in _get_json_dict
as_objects=False)
File "C:\Python34\lib\site-packages\praw\decorators.py", line 161, in wrapped
return_value = function(reddit_session, *args, **kwargs)
File "C:\Python34\lib\site-packages\praw\__init__.py", line 526, in request_json
data = json.loads(response, object_hook=hook)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
sys:1: ResourceWarning: unclosed <socket.socket fd=632, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('172.29.138.114', 50568), raddr=('198.41.208.139', 80)>
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=608, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('172.29.138.114', 50566), raddr=('198.41.208.142', 443)>
C:\Python34\lib\importlib\_bootstrap.py:2150: ImportWarning: sys.meta_path is empty
进程以退出代码 1 结束