Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PRAW/PYTHON,如何修复.comments函数中的400 HTTP响应?_Python_Api_Reddit_Praw - Fatal编程技术网

PRAW/PYTHON,如何修复.comments函数中的400 HTTP响应?

PRAW/PYTHON,如何修复.comments函数中的400 HTTP响应?,python,api,reddit,praw,Python,Api,Reddit,Praw,我正试图搜集reddit的评论,但我很难向reddit发送请求。似乎在我的短篇脚本的某个地方出现了一些糟糕的语法。有人能发现吗 我试过使用和不使用重定向uri。在我的Reddit应用程序页面下,显示我的应用程序已授权。我还尝试将用户名更改为用户名以外的其他名称,但仍然不起作用。我不确定还能提供什么其他信息 import praw #Python Reddit API Wrapper reddit = praw.Reddit(client_id='ID', \ #the personal num

我正试图搜集reddit的评论,但我很难向reddit发送请求。似乎在我的短篇脚本的某个地方出现了一些糟糕的语法。有人能发现吗

我试过使用和不使用重定向uri。在我的Reddit应用程序页面下,显示我的应用程序已授权。我还尝试将用户名更改为用户名以外的其他名称,但仍然不起作用。我不确定还能提供什么其他信息

import praw #Python Reddit API Wrapper

reddit = praw.Reddit(client_id='ID', \ #the personal number
                     client_secret='SECRET', \ #the secret number
                     user_agent='Username', \ #Identical to username
                     username='Username', \ #Identical to user_agent
                     password='PW', \ 
                     redirect_uri='http://localhost:8080')

#confirm connection:
print(reddit.user.me()) # this works and returns my Username

submission = reddit.submission("https://www.reddit.com/r/funny/comments/ch6oz0/amasian/")
submission.comments #this fails and returns:

  File "/lib/python3.6/site-packages/prawcore/sessions.py", line 130, in _request_with_retries
    raise self.STATUS_EXCEPTIONS[response.status_code](response)

BadRequest: received 400 HTTP response
submission()认为我输入了一个ID,因为我没有指定url=''


各位,请不要太悲伤,案件已结案。

我已将重定向uri更改为“排除”:8080',然后我设法获得了授权的代码和状态。接下来,我能够使用该代码检索刷新令牌。我已经升级了requests包,但到目前为止,所有这些都没有产生任何影响。从未真正解决过这个问题。我切换到使用praw.Reddit(…).subreddit.stream.comments中的stream.comments,然后实时插入到postgresql数据库中。这对于我的项目来说已经足够了,所以我暂时不再更新这个线程。
help(reddit.submission)
Help on method submission in module praw.reddit:

submission(id=None, url=None) method of praw.reddit.Reddit instance
    Return a lazy instance of :class:`~.Submission`.

    :param id: A reddit base36 submission ID, e.g., ``2gmzqe``.
    :param url: A URL supported by
        :meth:`~praw.models.Submission.id_from_url`.`.

    Either ``id`` or ``url`` can be provided, but not both.