# Urllib traceback error

**URL:** https://discuss.python.org/t/urllib-traceback-error/20722
**Category:** Python Help
**Created:** [November 3, 2022, 6:32pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722 "2022-11-03T18:32:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![drsarahroot](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/drsarahroot/32/9644_2.png) [@drsarahroot](https://discuss.python.org/u/drsarahroot)
#### Post date: [November 3, 2022, 6:32pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/1 "2022-11-03T18:32:22Z")

</div>

I am learning python and am very new to the whole thing, learning through a MOOC. This week our lesson was about scraping data from web sources. I cannot even get the most basic thing to work, getting a million traceback errors with this code. Can anyone help me understand what the error(s) is/are?

```auto
import urllib.request, urllib.parse, urllib.error

x = urllib.request.urlopen('https://py4e-data.dr-chuck.net/comments_42.html').read()

```

Here are the traceback errors I get when running this from Terminal  
Traceback (most recent call last):  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 1348, in do\_open  
h.request(req.get\_method(), req.selector, req.data, headers,  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 1282, in request  
self.\_send\_request(method, url, body, headers, encode\_chunked)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 1328, in \_send\_request  
self.endheaders(body, encode\_chunked=encode\_chunked)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 1277, in endheaders  
self.\_send\_output(message\_body, encode\_chunked=encode\_chunked)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 1037, in \_send\_output  
self.send(msg)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 975, in send  
self.connect()  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py”, line 1454, in connect  
self.sock = self.\_context.wrap\_socket(self.sock,  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 513, in wrap\_socket  
return self.sslsocket\_class.\_create(  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 1071, in \_create  
self.do\_handshake()  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 1342, in do\_handshake  
self.\_sslobj.do\_handshake()  
ssl.SSLCertVerificationError: [SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File “/Users/ser41/Library/CloudStorage/OneDrive-ThePennsylvaniaStateUniversity/Data Science/Python Michigan/Homework Assignments/Exercise 12.py”, line 4, in   
with urllib.request.urlopen(‘[Welcome to the comments assignment from www.py4e.com](https://py4e-data.dr-chuck.net/comments_42.html)’) as response:  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 216, in urlopen  
return opener.open(url, data, timeout)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 519, in open  
response = self.\_open(req, data)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 536, in \_open  
result = self.\_call\_chain(self.handle\_open, protocol, protocol +  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 496, in \_call\_chain  
result = func(\*args)  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 1391, in https\_open  
return self.do\_open(http.client.HTTPSConnection, req,  
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py”, line 1351, in do\_open  
raise URLError(err)  
urllib.error.URLError: \<urlopen error [SSL: CERTIFICATE\_VERIFY\_FAILED] certificate verify failed: unable to get local issuer certificate (\_ssl.c:997)\>

---

<div class="post-metadata">

### Author: ![abdnafees](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abdnafees/32/9551_2.png) [@abdnafees](https://discuss.python.org/u/abdnafees)
#### Post date: [November 3, 2022, 6:37pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/2 "2022-11-03T18:37:20Z")

</div>

It seems like you would have to provide an SSL certificate in order to receive the response otherwise the request might be considered as a threat.

---

<div class="post-metadata">

### Author: ![drsarahroot](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/drsarahroot/32/9644_2.png) [@drsarahroot](https://discuss.python.org/u/drsarahroot)
#### Post date: [November 3, 2022, 6:40pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/3 "2022-11-03T18:40:59Z")

</div>

Oh wow, this wasn’t covered in our class – do you have a link on how to do that?

Also, if I remove the s (which I assume has something to do with security), there is still a webpage with the info I need – if I do this, do I still need a certificate?

Thanks so much for your help!

---

<div class="post-metadata">

### Author: ![abdnafees](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abdnafees/32/9551_2.png) [@abdnafees](https://discuss.python.org/u/abdnafees)
#### Post date: [November 3, 2022, 6:44pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/4 "2022-11-03T18:44:46Z")

</div>

No worries.

Removing the s won’t be helpful as the URL doesn’t exist if they use HTTPS.

And yeah, this link might be able to help you out.

> <https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error>

---

<div class="post-metadata">

### Author: ![drsarahroot](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/drsarahroot/32/9644_2.png) [@drsarahroot](https://discuss.python.org/u/drsarahroot)
#### Post date: [November 3, 2022, 6:47pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/5 "2022-11-03T18:47:21Z")

</div>

In this case, fortunately, there is a non-secured website with the info I need – but this is super helpful since I am new to everything!

---

<div class="post-metadata">

### Author: ![abdnafees](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abdnafees/32/9551_2.png) [@abdnafees](https://discuss.python.org/u/abdnafees)
#### Post date: [November 3, 2022, 6:48pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/6 "2022-11-03T18:48:13Z")

</div>

Yeah, that sounds great. Have fun!

---

<div class="post-metadata">

### Author: ![oldblueday](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/oldblueday/32/7603_2.png) [@oldblueday](https://discuss.python.org/u/oldblueday)
#### Post date: [December 11, 2022, 3:41am UTC](https://discuss.python.org/t/urllib-traceback-error/20722/7 "2022-12-11T03:41:01Z")

</div>

I had the very same problem and am very grateful to all who have posted here. I’m also learning Python using courses on LinkedIn Learning, and came across the same error.

The Stack Overflow paged linked to [another](https://stackoverflow.com/questions/40684543/how-to-make-python-use-ca-certificates-from-mac-os-truststore) which gave two solutions:

1. Using finder, navigate to /Applications/Python 3.11 and double click on `Install Certificates.command` (this worked)
2. Run `pip install certifi` (this didn’t work)

In case any other newbies like myself run into the same, that’s what worked. Since I’m using all of this as a learning opportunity, is it possible to run this file from the command line? I couldn’t. The [file itself](https://gist.github.com/marschhuynh/31c9375fc34a3e20c2d3b9eb8131d8f3) looks like a Python file, but `python3 "Install Certificates.command"` didn’t do anything.

---

<div class="post-metadata">

### Author: ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)
#### Post date: [December 11, 2022, 11:21am UTC](https://discuss.python.org/t/urllib-traceback-error/20722/8 "2022-12-11T11:21:53Z")

</div>

> [@oldblueday](#):
>
> - Using finder, navigate to /Applications/Python 3.11 and double click on `Install Certificates.command` (this worked)
> - Run `pip install certifi` (this didn’t work)

The certifi package updates quite frequently (not too surprising). Basically, anytime I executed `apt update <anything>` on my Linux laptop, a new version would come along for the ride.

Can you explain what didn’t work about the `pip install` command? I can think of a few possible causes.

- You might need to be root.
- The certifi package was probably already installed, so you’d have to tell pip to update it: `pip install --upgrade certifi`.
- You might well not have found pip at all. `python -m pip` is generally better. Even so, the actual python executable in a Mac package won’t be on your PATH, so you’d have to give the full path to the Python binary.

---

<div class="post-metadata">

### Author: ![oldblueday](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/oldblueday/32/7603_2.png) [@oldblueday](https://discuss.python.org/u/oldblueday)
#### Post date: [December 11, 2022, 2:16pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/9 "2022-12-11T14:16:31Z")

</div>

```auto
% pip install certifi
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (2022.12.7)

```

Now, of course, it works. ¯\_(ツ)\_/¯  
Thank you for the hints, though.

---

<div class="post-metadata">

### Author: ![smontanaro](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/smontanaro/32/1389_2.png) [@smontanaro](https://discuss.python.org/u/smontanaro)
#### Post date: [December 11, 2022, 6:58pm UTC](https://discuss.python.org/t/urllib-traceback-error/20722/10 "2022-12-11T18:58:41Z")

</div>

Of course. The car is rattling, driving the owner nuts. They take it to the mechanic and the rattle mysteriously disappears. A couple weeks later, it’s back. 😉

Wait a few weeks and try

```auto
pip install -U certifi

```

If there is a new version, it will be installed.
