我收到错误消息:Traceback(最近一次通话):

时间:2019-07-17 16:53:00

标签: python windows

当我尝试运行我的代码时,出现错误:回溯(最近一次调用最近):

我在Windows 7操作系统上使用Python 2.7.15。我的代码和错误如下。

代码

import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
file = open('list.txt', 'r').read().split('\n')
for link in file:
        if link == "":
                continue
        url = "https://example.com/get/?host="+link+"&t=1"
        text = requests.get(url, headers=headers).text
        soup = BeautifulSoup(text, 'html.parser')
        narrow = soup.find('table', attrs={'border':'1'})
        if narrow == None:
            continue
        domain = narrow.findAll('td', attrs={'align':None})[2:]
        for line in domain:
            if line == "":
                continue
            open('result.txt', 'a+').write('http://'+line.text+'\n')
            print('\033[1;32;40m http://'+line.text)

错误

$ python rev.py
Traceback (most recent call last):
  File "rev.py", line 10, in <module>
    text = requests.get(url, headers=headers).text
  File "C:\Python27\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python27\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Python27\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python27\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='example.com', port=443): Max retries exceeded with url: /get/?host=ecocitoyens.ci&t=1 (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)'),))

0 个答案:

没有答案