When testing on a real device, especially a popular device or a device that is currently being used, you may start your test and after 10 minutes see an error:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='ondemand.us-west-1.saucelabs.com', port=443): Max retries exceeded with url: https://ondemand.us-west-1.saucelabs.com:443/wd/hub/session/d86df520-f6ed-4599-af4c-f8deed4c9792?ref=6fed2597-e560-4484-b1e8-41aa196f19fe (Caused by ResponseError('too many redirects',))
The Python bindings use urllib3 to create HTTP connections and by default urllib3 has a 3 retry limit.
Sauce Labs sends a 303 HTTP redirect every ~3 minutes (175 seconds).
Normally, Sauce Labs has a 15 minute limit on device creation requests and terminates the session afterwards with:
Unable to allocate device within 900000ms or 3 tries.
... but given the three redirect limit the session reaches 700 seconds and this never happens.
Solution
We recommend using dynamic allocation to ensure that a device matching your criteria is available at the start of the test. You can learn more here.
If you have to test with a specific device or using private devices, we recommend taking advantage of our REST API and checking the device is available before your test starts.
You can learn more here.