微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用 PRAW 获取热门帖子时出现超时错误

如何解决尝试使用 PRAW 获取热门帖子时出现超时错误

def generate_images():
    while True:
        try:
            reddit = praw.Reddit(client_id="",client_secret="",user_agent="",username="",password="")

            subreddit = reddit.subreddit("Art")
            pictures = []

            for submission in subreddit.hot(limit=32):
                imgurL = requests.get(f"https://www.reddit.com/{submission.id}/.json",headers={'User-agent': 'your bot 0.1'}).json()[0]['data']['children'][0]['data']['url']

                pictures.append(imgurL)
            break
        except Exception as error:
            print(error)
            continue

    return pictures[2:][::-1]

我正在尝试从 Art subreddit 生成指向图像的链接列表,但是我不断收到以下错误

('Connection aborted.',TimeoutError(10060,'A connection attempt Failed because the connected party did not properly respond after a period of time,or established connection Failed because connected host has Failed to respond',None,10060,None))

error with request HTTPSConnectionPool(host='www.reddit.com',port=443): Read timed out. (read timeout=16.0)

error with request HTTPSConnectionPool(host='oauth.reddit.com',port=443): Read timed out. (read timeout=16)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。