Forums

retries not function in my current console but works fine in other compiler

I have tested the code below and it does not retry in my console but work in online compiler like Replit https://replit.com/join/yeyleavl-jasonv4

As you can see,in the REPlit compiler when the script run, it takes sometimes to test an URL (the URL is consistently fail with 503) which is correct. However, in PAW, it straight away fail no matter I increase the retry to a larger number or increase the backoff factor which is not desirable. Please check and you can access my testurl.py to test it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/usr/bin/python
print "hello from python 2"
from lxml import html
import requests
from requests.packages.urllib3.util.retry import Retry
from requests.adapters import HTTPAdapter
import requests

print("Hello world")
url = 'http://httpstat.us/503'
s = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[ 502, 503, 504 ])
s.mount('http://', HTTPAdapter(max_retries=retries))
response = s.get(url)
print (response)
print ("abc")

I'd guess that you're not getting a 502, 503 or 504 status code from the endpoint. Check the status that you're actually getting from the endpoint.

Nope. This endpoint is consistently get 503. I have demonstrated to you. Click on the link https://replit.com/join/yeyleavl-jasonv4

Only fail with paw

You can login my account and access testurl.py that fail to work as expected

I don't mean check it from a browser. I mean check it in your code.

As I said, it works in https://replit.com/join/yeyleavl-jasonv4

So why the same code not work in paw? Do you able to explain? Do you really opened and have a look of the link I provided? I also stressed that the endpoint is made to return 503. So, I can't think of a reason why it s not work in PAW except something not working at your side. Click on the link, you will understand

It is Friday, I hope your side can check and confirm

https://replit.com/join/yeyleavl-jasonv4 It retries and take one minute to fail. (working correctly)

Pythonanywhere, it never retry and fail instantly. (not working correctly) .testurl.py is the evidence it failed.

Something not working correctly in your system of the modules I used?

I understand your issue. I don't need to visit the site to understand it. There could be many reasons why the code runs differently (different versions of Python, different versions of modules, different network environments etc.) and my suggestions are starting on the path to working out where the important differences are.