urequests
-
urequests takes 20-30s to throw an OSError if it doesn't get a response. We can't figure out where this timeout comes from. There is no timeout in the original requests library
def request(method, url, data=None, json=None, headers={}, stream=None): try: proto, dummy, host, path = url.split("/", 3) except ValueError: proto, dummy, host = url.split("/", 2) path = "" if proto == "http:": port = 80 elif proto == "https:": import ussl port = 443 else: raise ValueError("Unsupported protocol: " + proto) if ":" in host: host, port = host.split(":", 1) port = int(port) ai = usocket.getaddrinfo(host, port) ai = ai[0] s = usocket.socket(ai[0], ai[1], ai[2])We thought we'd try to add a shorter timeout following https://docs.python.org/3/library/socket.html#socket.getaddrinfo
def request(method, url, data=None, json=None, headers={}, stream=None, timeout=5): try: proto, dummy, host, path = url.split("/", 3) except ValueError: proto, dummy, host = url.split("/", 2) path = "" if proto == "http:": port = 80 elif proto == "https:": import ussl port = 443 else: raise ValueError("Unsupported protocol: " + proto) if ":" in host: host, port = host.split(":", 1) port = int(port) s = usocket.socket(2,1,0) if timeout is not None: assert hasattr(usocket.socket, 'settimeout'), 'Socket does not support timeout' s.settimeout(timeout) ai = usocket.getaddrinfo(host, port) ai = ai[0]but it's not giving the 5s timeout we'd like. Can anyone see a way forward with this?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login