Home > database >  How can i make an automaticly retry after post request fails
How can i make an automaticly retry after post request fails

Time:11-29

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

CodePudding user response:

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.

  • Related