Key Press Not Working
I am trying to catch a key press but it is not working. How can I fix this code? There is no error message so there is no error message to do a search on. I am using Python3.5 64-bit inside the terminal. while True: key = input("Enter a letter: ") if key == ord('q'): break The loop keeps running even though I have pressed the letter 'q'. -- https://mail.python.org/mailman/listinfo/python-list
Try: Except: evaluates to True every time
I have this code that tests a server to see if it is listening on port 123 runs and evaluates to True every time. Even if the server does not exist but it is not supposed to do that. I am getting no error message at all. What is going on with this code? #!/usr/bin/env python import socket hostname = ["192.168.1.22", "192.168.1.23", "200.168.1.24", "19.0.0.0"] port = 123 def check_udp(hosts, port_num): '''Test the UDP port on a remove server.''' s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for host in hosts: try: s.connect((host, port_num)) return "Port 53 is reachable on: %s" % host except socket.error as e: return "Error on connect: %s" % e check_udp(hostname, port) -- https://mail.python.org/mailman/listinfo/python-list
Try Except Specific Error Messages
Hi, I am try to get more specific error messages using try/except. I ran this code with the cable unplugged to see the error message. I got #!/usr/bin/env python3 import urllib.request webpage = urllib.request.urlopen("http://fakewebsite.com/";) text = webpage.read().decode("utf8") I got two errors. This: [] socket.gaierror: [Errno -2] Name or service not known and this: [] urllib.error.URLError: I tried this but got more error messages. try: webpage = urllib.request.urlopen("http://fakewebsite.com/";) text = webpage.read().decode("utf8") except URLError as err: print("URLError: " + str(err)) How do I wrap urllib.request with try/except? -- https://mail.python.org/mailman/listinfo/python-list