如何修复urllib.error.HTTPError:HTTP错误406:不可接受

时间:2019-08-13 02:26:53

标签: python python-3.x

我正在使用ipwhois PyPI,代码可以检查IP并给出输出,但偶尔会出现错误:

  raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 406: Not Acceptable"

During handling of the above exception, another exception occurred:

socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

我正在使用Sublime Text Editor进行编码

import requests
import os,sys
from bs4 import BeautifulSoup
import pandas as pd
from ipwhois import IPWhois

class IPCheck():
    ip = input ("Enter Source IP Address: ")

    def __init__(self):
        pass
    def whoip(self):
        obj = IPWhois(self.ip)
        results = obj.lookup_rws()
        print("\nSource IP Details and Analysis: \n\nWHOIS IP Lookup Results: \n------------------------\nOrg Name: {}".format(results['nets'][0]['description']))
        print("Range: {}".format(results['nets'][0]['range']))
        print("Handle: {}".format(results['nets'][0]['handle']))
        print("Registration Date: {}".format(results['nets'][0]['created']))
        print("Address: {}".format(results['nets'][0]['address']))
        print("City: {}".format(results['nets'][0]['city']))
        print("State/Province: {}".format(results['nets'][0]['state']))
        print("Country: {}".format(results['nets'][0]['country']))
        print("Postal Code: {}".format(results['nets'][0]['postal_code']))

IPC=IPCheck()
IPC.whoip()

这是错误回溯:

Traceback (most recent call last):
  File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 406: Not Acceptable                         During handling of the above exception, another exception occurred:                \AppData\Local\Programs\Python\Python37-32\lib\site-packages\ipwhois\ipwhois.py", line 701, in get_rws
    url)
ipwhois.ipwhois.WhoisLookupError: Whois RWS lookup failed for 'http://rdap.lacnic.net/rdap/ip/201.220.29.49'.

0 个答案:

没有答案