Reddit PRAW Failing to autenticate due to SSL error

Home / Uncategorized / Reddit PRAW Failing to autenticate due to SSL error

Question:
My code is currently this:from bs4 import BeautifulSoup
from urllib.parse import urlparse

import requests
import praw
import time
import re
import bs4

USERAGENT = ‘web:PeskyTrollBot:v0.1 (by /u/redacted)’
PASSWORD = ‘NOTREALLYMYPASSWORD’
USERNAME = "PeskyTrollBot"
ID = ‘redacted’
SECRET = ‘redacted’

def authenitcate():print("Authenticating…")
reddit = praw.Reddit(client_id=ID, client_secret=SECRET,
password=PASSWORD, user_agent=USERAGENT,
username=USERNAME)
print("Authenticated as {}n" .format(reddit.user.me()))
return reddit

authenitcate()

and my console output is as follows:C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32python.exe C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py
Authenticating…
Traceback (most recent call last):File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 595, in urlopen
self._prepare_proxy(conn)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 816, in _prepare_proxy
conn.connect()
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connection.py", line 326, in connect
ssl_context=context)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilssl_.py", line 329, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libssl.py", line 808, in __init__
self.do_handshake()
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

During handling of the above exception, another exception occurred:
Traceback (most recent call last):File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 440, in send
timeout=timeout
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesurllib3utilretry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=’www.reddit.com’, port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)’),))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcorerequestor.py", line 47, in request
return self._http.request(*args, timeout=TIMEOUT, **kwargs)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesrequestssessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesrequestsadapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=’www.reddit.com’, port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)’),))

During handling of the above exception, another exception occurred:
Traceback (most recent call last):File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 23, in
authenitcate()
File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 20, in authenitcate
print("Authenticated as {}n" .format(reddit.user.me()))
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawmodelsuser.py", line 60, in me
user_data = self._reddit.get(API_PATH[‘me’])
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawreddit.py", line 367, in get
data = self.request(‘GET’, path, params=params)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawreddit.py", line 472, in request
params=params)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 175, in request
params=params, url=url)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 121, in _request_with_retries
retries, saved_exception, url)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 87, in _do_retry
params=params, url=url, retries=retries – 1)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 121, in _request_with_retries
retries, saved_exception, url)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 87, in _do_retry
params=params, url=url, retries=retries – 1)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 109, in _request_with_retries
data, files, json, method, params, retries, url)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 94, in _make_request
params=params)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcorerate_limit.py", line 32, in call
kwargs[‘headers’] = set_header_callback()
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoresessions.py", line 135, in _set_header_callback
self._authorizer.refresh()
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoreauth.py", line 328, in refresh
password=self._password)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoreauth.py", line 138, in _request_token
response = self._authenticator._post(url, **data)
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcoreauth.py", line 29, in _post
data=sorted(data.items()))
File "C:UsersJoshLaptopAppDataLocalProgramsPythonPython36-32libsite-packagesprawcorerequestor.py", line 49, in request
raise RequestException(exc, args, kwargs)
prawcore.exceptions.RequestException: error with request HTTPSConnectionPool(host=’www.reddit.com’, port=443): Max retries exceeded with url: /api/v1/access_token (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)’),))

Process finished with exit code 1

I have tried multiple suggestions from other stackoverflow posts such as updating my useragent to fit the Reddit guidelines for one. I have tried telling it not to verify ssl certificates right after I created the praw object and the error still persists. I also tried using a try catch loop with a minute sleep after each catch to no avail. any ideas for troubleshooting? I’ve ran out of tips from other posts so I now am making my own.


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *