How to set PROXIES for requests?
See original GitHub issueI was looking for a way to set proxy in order to make requests. At the moment I’ve patched base backend:
proxies = getattr(settings, 'SOCIAL_SERVICES_PROXIES', {})
old_request = BaseAuth.request
@wraps(old_request)
def new_request(self, url, method='GET', *args, **kwargs):
'''
COPY-PASTE from social_core.backends.base import BaseAuth
with proxy support
'''
kwargs.setdefault('headers', {})
if self.setting('VERIFY_SSL') is not None:
kwargs.setdefault('verify', self.setting('VERIFY_SSL'))
kwargs.setdefault('timeout', self.setting('REQUESTS_TIMEOUT') or self.setting('URLOPEN_TIMEOUT'))
if self.SEND_USER_AGENT and 'User-Agent' not in kwargs['headers']:
kwargs['headers']['User-Agent'] = self.setting('USER_AGENT') or user_agent()
kwargs.setdefault('proxies', proxies) # main line
try:
if self.SSL_PROTOCOL:
session = SSLHttpAdapter.ssl_adapter_session(self.SSL_PROTOCOL)
response = session.request(method, url, *args, **kwargs)
else:
response = request(method, url, *args, **kwargs)
except ConnectionError as err:
LOG.info(str(kwargs))
LOG.error(str(err))
raise AuthFailed(self, str(err))
response.raise_for_status()
return response
BaseAuth.request = new_request
Is there a better way to do that?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Using a Proxy Server with Python requests - Datagy
In order to use proxies in the requests Python library, you need to create a dictionary that defines the HTTP, HTTPS, and FTP...
Read more >Proxies with Python 'Requests' module - Stack Overflow
If you need to use a proxy, you can configure individual requests with the proxies argument to any request method: import requests proxies...
Read more >How to use proxies with Python Requests Proxy Module - Zyte
In this part, we're going to cover how to configure proxies in Requests. To get started we need a working proxy and a...
Read more >How do I use a proxy server with Python Requests? - ReqBin
Another way to pass a proxy address to Python is to set the http_proxy and https_proxy environment variables. If you set environment variables, ......
Read more >Requests behind corporate proxies in Python - Plotly
Note that proxy URLs must include the scheme. You may also see this error if your proxy variable is set but you are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@msadig Usually I create ‘adapters’ app for such purposes. Then I define AppConfig for each 3rd party lib patching and import exect patch in
ready
method. So I can include those apps in a right place inINSTALLED_APPS
.A
SOCIAL_AUTH_PROXIES
config var seems to have been quietly added for this use case in 25ed3b6242e89f644b3d4a4d235496905b4bc9c1 as part of the 3.4.0 release.