PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 5, 2022

[FIXED] how do i catch SSL: CERTIFICATE_VERIFY_FAILED error python?

 August 05, 2022     exception, python, ssl, ssl-certificate, urllib3     No comments   

Issue

I am using urllib3.PoolManager to make http requests. And in some part of my code I use this code to make a request

resp = h.request(self.method, self.url, body=body, headers=headers, timeout=TIMEOUT, retries=retries)

and I get the error SSL: CERTIFICATE_VERIFY_FAILED. Below is the full stack trace.

  File "/lib/python2.7/site-packages/urllib3/request.py", line 69, in request
    **urlopen_kw)

  File "/lib/python2.7/site-packages/urllib3/request.py", line 90, in request_encode_url
    return self.urlopen(method, url, **extra_kw)

  File "/lib/python2.7/site-packages/urllib3/poolmanager.py", line 248, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)

  File "/lib/python2.7/site-packages/urllib3/connectionpool.py", line 621, in urlopen
    raise SSLError(e)

[SSL: CERTIFICATE_VERIFY_FAILED]

The error is expected. But the problem is I cannot catch the error in try except block.

I tried to use

 except ssl.SSLError:

but that does not catch this error. I also tried ssl.CertificateError but no results. I can catch it by using the Exception class but I need to catch the specific errors and handle them differently. Can someone please find me a solution to this?


Solution

I found the solution. The exception class that was being raised is urllib3.exceptions.SSLError.



Answered By - vishal
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing