Skip to content Skip to sidebar Skip to footer

Using Urllib Gives Ssl Error

Running a request with urllib but continuously receive this error: Traceback (most recent call last): File '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib

Solution 1:

I had this issue not so long ago. Try giving the following commands a go:

  1. pip install requests[security]

If that doesn't work, try the following:

  1. pip install pyOpenSSL
  2. pip install cryptography
  3. pip install idna

Solution 2:

Try the requests module. I am using a windows, so try the mac equivalent of a pip install. With Python 3.6, I believe that urllib has been having some issues. If you are trying to webscrape, the requests module is better for Python 3, than the urllib module.

Below is an example from the other day when I was webscraping Wikipedia for stock tickers:

response = requests.get("https://en.wikipedia.org/wiki/List_of_S26P_500_companies")
          soup = bs4.BeautifulSoup(response.text)

I got the url by using the requests module, and then was able to work with the text using beautiful soup. From what I gathered, urllib is to be avoided at all times for Python 3+ and is more suitable for Python 3. Try to do exactly what you're doing, but via the requests module instead of urllib.

Post a Comment for "Using Urllib Gives Ssl Error"