Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    urequests

    Scheduled Pinned Locked Moved Discussion
    1 Posts 1 Posters 226 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      kjm
      last edited by

      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?

      1 Reply Last reply Reply Quote 0

      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
      • 1 / 1
      • First post
        Last post

      Pycom on Twitter

      Pycom