Skip to content Skip to sidebar Skip to footer

Sslerror With Praw?

I'm trying to get started with PRAW but I'm having issues using login(). I have the following piece of code: import praw r = praw.Reddit('This is a test bot') r.login('myRedditUse

Solution 1:

TL;DR:_ssl_urldoesn't work in PRAW 4. Use a custom Requests session with Session.verify.

For PRAW 4 or later:

According to PRAW's developer, the option to use config._ssl_url = None was removed in PRAW 4. Instead, you can use a custom Requests Session to configure your own SSL settings.

Assuming you are on a company network with self-signed certificates, you have two options.

Option 1 - Trusting a Self-Signed Certificate

First, export your company's root certificate as a .pem file. (See Export a PEM-Format Certificate From a Windows System)

Next, create a Requests session and specify a path directly to your certificate file.

import praw
import requests

session = requests.Session()
session.verify = '/path/to/certfile.pem'# Path to cert file
reddit = praw.Reddit(client_id='###',
                     client_secret='###',
                     user_agent='windows:testapp (by /u/stevoisiak)',
                     requestor_kwargs={'session': session})

Option 2 - Disabling SSL Verification (insecure)

This method will fully disable HTTPS verification for all requests. While this method is simple, it is strongly discouraged for security reasons. (See SSL Warnings)

import praw
import requests

session = requests.Session()
session.verify = False# Disable SSL
reddit = praw.Reddit(client_id='###',
                     client_secret='###',
                     user_agent='windows:testapp (by /u/stevoisiak)',
                     requestor_kwargs={'session': session})

See Also

Solution 2:

According to praw SSLError during login from shared hosting:

It appears that your host doesn't have the proper SSL certificates installed. You can disable using SSL (not recommended) by adding

r.config._ssl_url = None

after you create the PRAW object.

Solution 3:

UPD: made the error go away by adding my company's internal certificate to the cacert.pem file.

Below the steps:

  1. Find the internal certificate that your browser is using and export it as the Base64 encoded format. The details are described here: How to find the path to a SSL cert file?
  2. Find the cacert.pem file that the request package is using (..\Lib\site-packages\request) and copy past at the end of the cacert.pem file everything from your internal certificate file.

This is my old answer, I temporary fixed the problem by turning off SSL verification

I had the same issue on Windows 7, not only with login, but with any request to reddit. r.config._ssl_url = None didn't do the trick either, after creating praw.ini as C:\users\&user_name\AppData\Roaming\praw.ini:

[reddit]
validate_certs:False

I finally made it work. Though I have the InsecureRequestWarning warning. Wanted to throw that here in case if someone like me is still struggling with that.

Post a Comment for "Sslerror With Praw?"