Search code examples
python-3.xproxypraw

How can proxies be added to Praw without using environment variables?


I'm trying to test out proxies when using Praw module for Python, and have found some information on setting environment variables. I'm trying to ascertain whether there is a direct way of using proxies as a keyword for additional to the Reddit() initializer?

I've tried looking everywhere for more information about this, and thought that using proxies with Praw would be more widely-documented.


Solution

  • If you configure a custom Session, you can accomplish this without environment variables. You need to modify Session.proxies.

    import praw
    from requests import Session
    
    session = Session()
    session.proxies['https'] = 'https://localhost:3128'
    reddit = praw.Reddit(client_id='SI8pN3DSbt0zor',
                         client_secret='xaxkj7HNh8kwg8e5t4m6KvSrbTI',
                         password='1guiwevlfo00esyy',
                         requestor_kwargs={'session': session},  # pass Session
                         user_agent='testscript by /u/fakebot3',
                         username='fakebot3')