Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am getting the following error:

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)>

This is the code that is causing this error:

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)

The API I'm using requires me to use HTTPS. How can I make it bypass the verification?

1 Answer

0 votes
by (106k points)

To get rid of this error you can use the below-mentioned code:-

import requests 

requests.packages.urllib3.disable_warnings() 

import ssl 

try:

_create_unverified_https_context = 

ssl._create_unverified_context 

except AttributeError: 

pass 

else: 

ssl._create_default_https_context =

 _create_unverified_https_context

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...