omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    'No route to host' error in beta 340009 when using multicast

    Pythonista
    beta networking bug report
    3
    5
    104
    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.
    • ttobias
      ttobias last edited by ttobias

      Hi,

      I have a script to discover devices on the local network which seems to no longer work.

      The error is:
      ssdp_socket.sendto('\r\n'.join(msg).encode('ascii'), (dst, 1900))
      OSError: [Errno 65] No route to host

      I know this worked before but not sure when.
      I just started using Pythonista again with the new beta.
      Could it be that the beta does not have the Multicast Networking capability?
      https://developer.apple.com/forums/thread/715204

      Minimal example:

      import socket
      import sys
      
      dst = "239.255.255.250"
      port = 1900
      
      msg = [
          'M-SEARCH * HTTP/1.1',
          f'Host:{dst}:{port}' ,
          'ST:upnp:rootdevice',
          'Man:"ssdp:discover"',
          'MX:1',
          '']
      
      ssdp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
      ssdp_socket.settimeout(10)
      ssdp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
      ssdp_socket.sendto('\r\n'.join(msg).encode('ascii'), (dst, port))
      
      while True:
          try:
              data, addr = ssdp_socket.recvfrom(32*1024)
          except socket.timeout as e:
              print(f"{e = }")
              break
          print("[+] %s\n%s" % (addr, data.decode('ascii')))
      

      (Edited based on @ccc suggestion)

      Thanks

      ccc 1 Reply Last reply Reply Quote 0
      • ccc
        ccc @ttobias last edited by ccc

        @ttobias said in 'No route to host' error in beta 340009 when using multicast:

        except socket.timeout:
            break
        

        Change that to this...

            except socket.timeout as e:
                print(f"{e = }")
                break
        
        ttobias 1 Reply Last reply Reply Quote 0
        • ttobias
          ttobias @ccc last edited by

          @ccc Makes sense, I changed it in the code if someone wants to use the code.
          But the error is happening in the line above the while loop.

          The .sendto(...) is already failing with the 'No route to host' error.
          The script works fine if executed on a desktop, so I assume it might be related to the missing capability.

          omz 1 Reply Last reply Reply Quote 0
          • omz
            omz @ttobias last edited by

            @ttobias It looks like multicast networking requires an additional entitlement from Apple that I have to apply for, and explain why my app needs this... I think the previous version might still have worked because it was built with an older iOS SDK. I'll look into this, but it might take a little while.

            ttobias 1 Reply Last reply Reply Quote 0
            • ttobias
              ttobias @omz last edited by ttobias

              @omz Thanks, sure no problem.
              It's definitely a special use case.
              If you can't convince Apple that's no major problem for me all around I'm very happy with the latest update.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors