PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 20, 2022

[FIXED] How to retry 'Connection aborted.', RemoteDisconnected('Remote end closed connection without response' error

 April 20, 2022     connection, exception, http, python-requests, urllib3     No comments   

Issue

def some_func(url):
    try:
        requests.get(url)
    except exception as e:
        # retry code here

I want to retry the request if the previous request gets a connection aborted error. How can I implement this?


Solution

From the requests docs:

s = requests.Session()
a = requests.adapters.HTTPAdapter(max_retries=3)
s.mount('http://', a)
s.mount('https://', a)

def some_func(url):
    s.get(url)

For finer retry behaviour see urrlib3's doc on Retry.



Answered By - Speedlulu
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing