Because we are doing some web data set processing, we need to resolve the domain name and organize Ip, so we use
Socket.getaddrinfo.
First, read the domain name from the previously processed domain name dataset
Secondly, loop through them one by one
Do the exception handling
But the results are obviously not as good as they should be, but when you manually put a single domain name in and resolve it, there is no problem.
I think the problem is a newline at the end of server_name.
So I need to remove the ‘\n’
To explain, there are two ways to remove line breaks here.
Method 1: With .sprip(‘\n’)
Method 2: [:-1] (because the line break is always in the last character)
I hope this will help and solve the problem smoothly and instantly.
def get_dns(): domains = DataDispose.get_domain_list() for domain in domains: try: myaddr = socket.getaddrinfo(domain[:-1], 'http') print(myaddr) except Exception as e: print(e) continue
Read More:
- Python: How to Set Line breaks and tabs for Strings
- [Solved] raise ContentTooShortError(urllib.error.ContentTooShortError: <urlopen error retrieval incomplete:
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- Python raspberry pie starts sending IP address to mailbox
- Crawler overtime error socket.timeout: timed out/NameError: name ‘socket‘ is not defined
- [Solved] Python Error: An attempt has been made to start a new process before the current process has finished …
- Python_Syntax error: unexpected character after line continuation character
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- [Solved] PyInstaller Error: ValueError: too many values to unpack
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [example multitasking] Python multithreading module
- [Modified] AttributeError: ‘socket‘ object has no attribute ‘ioctl‘ python linux
- Python uses try… Except… To output detailed errors
- tensorflow2.3 InvalidArgumentError: jpeg::Uncompress failed [How to Solve]
- [Solved] ValueError: check_hostname requires server_hostname
- How to Fix Python reading large local file memory error
- How to Solve Opencv Reads Video Error: cv2.error
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- Python algorithm for “anagram” judgment problem
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu