0

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 (after now having installed pyopenssl) is as follows:

    C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py
Authenticating...
Traceback (most recent call last):
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1716, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1456, in _raise_ssl_error
    _raise_current_error()
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
    conn.connect()
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connection.py", line 326, in connect
    ssl_context=context)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\ssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 448, in wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\util\retry.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("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.py", line 47, in request
    return self._http.request(*args, timeout=TIMEOUT, **kwargs)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.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("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 19, in <module>
    authenticate()
  File "C:/Users/JoshLaptop/PycharmProjects/practice/TestBot.py", line 16, in authenticate
    print("Authenticated as {}\n" .format(reddit.user.me()))
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\models\user.py", line 60, in me
    user_data = self._reddit.get(API_PATH['me'])
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\reddit.py", line 367, in get
    data = self.request('GET', path, params=params)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\praw\reddit.py", line 472, in request
    params=params)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 175, in request
    params=params, url=url)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 121, in _request_with_retries
    retries, saved_exception, url)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 87, in _do_retry
    params=params, url=url, retries=retries - 1)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 121, in _request_with_retries
    retries, saved_exception, url)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 87, in _do_retry
    params=params, url=url, retries=retries - 1)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 109, in _request_with_retries
    data, files, json, method, params, retries, url)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 94, in _make_request
    params=params)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\rate_limit.py", line 32, in call
    kwargs['headers'] = set_header_callback()
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\sessions.py", line 135, in _set_header_callback
    self._authorizer.refresh()
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 328, in refresh
    password=self._password)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 138, in _request_token
    response = self._authenticator._post(url, **data)
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\auth.py", line 29, in _post
    data=sorted(data.items()))
  File "C:\Users\JoshLaptop\AppData\Local\Programs\Python\Python36-32\lib\site-packages\prawcore\requestor.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("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Josh Peel
  • 87
  • 1
  • 10
  • Have you tried doing pip install pyopenssl? – jlaur Aug 15 '17 at 15:29
  • I have indeed done that. Did that after I made this post and the problem has changed but instead now just gives an openssl bad handshake error in place of the previous. Will update here soon. – Josh Peel Aug 15 '17 at 15:32
  • Have you tried closing your ide and opening it again? – jlaur Aug 15 '17 at 17:29
  • Yes I have fully rebooted. – Josh Peel Aug 15 '17 at 17:35
  • I've experience with that module. According to the doc you only need to import praw. What happens if you leave out the other imports - perhaps it's a namespace issue at the root cause? – jlaur Aug 15 '17 at 17:38
  • just tried. no change – Josh Peel Aug 15 '17 at 18:06
  • Apparently it's a 3.6 thing. Have tried inserting the reddit certificate manualle as proposed in this answer? https://stackoverflow.com/a/31915123/8240959 – jlaur Aug 15 '17 at 21:19
  • Will try that. Additionally I cannot install anything using pip without getting an ssl certificate validation failed error in 3.6.2 or 3.5.4. Very odd – Josh Peel Aug 15 '17 at 22:07
  • So if you go to terminal and do python -m pip install whatever_package you get and ssl error?!? – jlaur Aug 16 '17 at 06:45

0 Answers0