OutOfRetries: Repeated socket failures

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

OutOfRetries: Repeated socket failures

Post by teltech84 »

Does anyone know what this error message means?

Retrieving data...Traceback (most recent call last):
File "code.py", line 46, in <module>
File "code.py", line 40, in main
File "adafruit_pyportal/__init__.py", line 306, in fetch
File "adafruit_portalbase/network.py", line 478, in fetch
File "adafruit_requests.py", line 696, in get
File "adafruit_requests.py", line 578, in request
OutOfRetries: Repeated socket failures

I am running this code and after awhile I come back to my pyportal throwing this error message and I just want it to loop infinitely.

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal

i = 0
 
#Set up where we'll be fetching data from
DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
QUOTE_LOCATION = [i, "entryContent"]
AUTHOR_LOCATION = [i, "entryDate"]

#the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
var = (QUOTE_LOCATION, AUTHOR_LOCATION)
pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                    #status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/quote_background.bmp",
                    text_font=cwd+"/fonts/PTSans-BoldItalic.bdf",
                    text_position=((20, 120),  # quote location
                                (210, 210)), # author location
                    text_color=(0x008080,  # quote text color
                                0x8080FF), # author text color
                    text_wrap=(35, # characters to wrap for quote
                            0), # no wrap for author
                    text_maxlen=(190, 30), # max text size for quote & author
                )
pyportal.preload_font()



def main(i):
    print(i)
    pyportal.json_path=([str(i),
                        'entryContent'],
                        [str(i),
                        'entryDate'],
                        )
    # speed up projects with lots of text by preloading the font!
    value = pyportal.fetch()
    print("Response is", value)


while True:
    try:
        main(i)
        i = i + 1
        time.sleep(5)
        if i == 75: 
            i = 0
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
    time.sleep(5)

User avatar
retiredwizard
 
Posts: 49
Joined: Wed Sep 28, 2016 9:06 pm

Re: OutOfRetries: Repeated socket failures

Post by retiredwizard »

The loop in the library that throws that error opens an http socket, sends the request and then checks for a valid response. If any of those three operations fail it tries a second time and a second failure will throw your "OutOfRetries" message.

There is a timeout parameter used when opening the socket which might be attached to the optional timeout= parameter on pyportal.fetch(). The timeout defaults to 10 (seconds?), you might try upping that and see if it helps.

Failing that, it's a bit messy, but you could grab the python source of adafruit_requests from github, search for retry_count < 2 and replace the 2 with a larger number.
Last edited by retiredwizard on Fri Jan 28, 2022 11:35 pm, edited 1 time in total.

User avatar
retiredwizard
 
Posts: 49
Joined: Wed Sep 28, 2016 9:06 pm

Re: OutOfRetries: Repeated socket failures

Post by retiredwizard »

Well maybe an easier option that might work would be to put your pyportal.fetch() statement in a try:/except: block, or add the OutOfRetrys error to the list at the bottom or your while True: loop. :)

I'm assuming your code runs for a while and this is simply a short term Internet error that will recover itself. If it's something caused by a memory leak or broken socket just catching the error and retrying isn't going to help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”