我得到以下错误:

Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in        __bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in  run
self.__target(*self.__args, **self.__kwargs)
File "/Users/Matthew/Desktop/Skypebot 2.0/bot.py", line 271, in process
info = urllib2.urlopen(req).read()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1240, in https_open
context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>

下面是导致这个错误的代码:

if input.startswith("!web"):
    input = input.replace("!web ", "")      
    url = "https://domainsearch.p.mashape.com/index.php?name=" + input
    req = urllib2.Request(url, headers={ 'X-Mashape-Key': 'XXXXXXXXXXXXXXXXXXXX' })
    info = urllib2.urlopen(req).read()
    Message.Chat.SendMessage ("" + info)

我正在使用的API要求我使用HTTPS。我怎样才能让它绕过验证呢?


当前回答

Craig Glennie的回答是:

MacOs Sierra上的Python 3.6.1

在bash终端中输入这个可以解决问题:

pip install certifi
/Applications/Python\ 3.6/Install\ Certificates.command

其他回答

安装nltk的步骤(我已经在MAC OS X中安装了python3 (3.6.2)

sudo easy_install pip

使用ignore installed选项忽略卸载之前版本的6,否则,它会在卸载时给出一个错误,并且不进行电影转发

sudo pip3 install -U nltk --ignore-installed six

检查pip和python的安装,使用'3'版本

which python python2 python3
which pip pip2 pip3

检查NLTK是否安装

python3
import nltk
nltk.__path__
['/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nltk']

在安装示例之前安装SSL证书,否则我们将在安装示例时证书错误

/Applications/Python\ 3.6/Install\ Certificates.command
python3 -m nltk.downloader book

这就成功地完成了nltk和nltk_ata的安装

Python 2.7.12(默认,2016年7月29日,15:26:22)修复了上述问题。这个信息可能会帮助到其他人。

您可以使用以下命令在python中安装包

在木星笔记本上

!pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org --user [Pacakage name]

!pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org --user xgboost

请注意,我已经尝试在mac和windows中安装证书

我的解决方案是使用一个python包Beautiful Soup。它神奇地处理SSL的事情。Beautiful Soup是一个可以很容易地从网页中抓取信息的库。

from bs4 import BeautifulSoup as soup
import requests
url = "https://dex.raydium.io/#/market/2xiv8A5xrJ7RnGdxXB42uFEkYHJjszEhaJyKKt4WaLep"
html = requests.get(url, verify=True)
 
page_soup = soup(html.text, 'html.parser')
print(page_soup.prettify())

我通过关闭Fiddler(一个HTTP调试代理)来解决这个问题,检查是否启用了代理并重试。