Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i make an automaticly retry after post request fails

I need to code that Python retry after failed connection to website, like when i try to post a request & its fails that python automaticly retrys. I use post requests and when python fails to send the request the code will stop but i need that its retry!

I hope someone can help me
Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Do this,

while True:
    try:
         session.post(cart, data=payload, proxies=proxy)
         break
    except:
         continue

The main loop is a while True loop, it will continue forever unless it successfully completes the try statement. As long as there is an exception, it will go back to the top of the while loop.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading