如何增加 PSAW 最大重试次数

How to increase PSAW Max Retries

我在尝试使用 PSAW 从 pushshift.io 收集大量数据时不断收到以下错误。

异常:无法连接到 pushshift.io。超过最大重试次数。

如何增加“最大重试次数”才能避免这种情况发生?

my_reddit_submissions=api.search_submissions(before=int(end_epoch.timestamp()),
                                            post_hint='image',
                                            filter=['id','full_link','title', 'url', 'subreddit', 'author_fullname'],
                                            limit = frequency
                                            )


for submission_x in my_reddit_submissions:
           data_new=data_new.append(submission_x.d_, ignore_index=True)

顺便说一句,我的代码在一定程度上工作正常...

你应该看看这个问题[可能会有帮助]Max retries exceeded with URL in requests

服务器主动拒绝与您通信时引发此异常。如果您短时间内向服务器请求太多次,则可能会发生这种情况。

为了OverCome This,你应该等待几秒钟再重试

这是一个例子:

import time
import requests

with requests.Session() as session:
    while 1: # Infinite Loop used to send infinite requests to the server without waiting time
        try:
            response = session.get("https://www.example.com")           
        except requests.exceptions.ConnectionError:
            response.status_code = "Connection Refused By The Server"
            time.sleep(2) # Sleeping For 2 seconds to resolve the server overload error
        print(response.status_code)