0

I'm configured a jenkins job to run a python script that posts to a url for every 10 minutes and check if it is getting correct response using Python requests.

requests.post(url, verify=False, data=payload)

I'm getting no error at all almost everytime.

However, sometimes I'm getting 502 proxy error intermittently. But when I check the url manually at that time, I'm able to access the site with no issues.

What would be the real cause behind this 502 proxy error which is appearing intermittently. and Is there any workaround to avoid this error completely when using requests library?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • you can add a small sleep and retry a few times ... some point between their servers and your url endpoint is rejecting with bad gateway ... – Joran Beasley Nov 01 '18 at 22:17
  • Is there any better option in requests itself to handle such cases? I know that I can use `time.sleep()` for sleep. But just wondering if there is any other option in requests library itself. – Tyrion Lannister Nov 01 '18 at 22:20
  • See https://stackoverflow.com/a/35636367/7983309 or https://www.peterbe.com/plog/best-practice-with-retries-with-requests – ben5556 Nov 01 '18 at 22:27
  • Is this an issue from my side or with requests or something else? – Tyrion Lannister Nov 02 '18 at 09:26
  • it can happen on your side or at any hop on the route to your destination or at the server level itself ... chances are its one of the routes that it tries to take and some intermediate ISP... but its impossible to say for sure... you just have to implement retries... almost 100% it is not an issue with requests – Joran Beasley Nov 02 '18 at 20:46
  • Finally implemented retries with 2 minutes gap. Worked like charm. No issues. – Tyrion Lannister Nov 03 '18 at 15:45

0 Answers0