【问题标题】:How to increase PSAW Max Retries如何增加 PSAW 最大重试次数
【发布时间】:2022-01-21 16:53:42
【问题描述】:

尝试使用 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)

顺便说一句,我的代码工作正常...

【问题讨论】:

    标签: python web-scraping python-requests reddit praw


    【解决方案1】:

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

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

    克服这个问题,您应该等待几秒钟后再重试

    这是一个例子:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      相关资源
      最近更新 更多