Last active
January 31, 2016 18:19
-
-
Save wtrevino/c4ff3918914e4a80b793 to your computer and use it in GitHub Desktop.
How to set up Scrapy middleware with Proxymesh (or any other proxy service really...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxyMeshMiddleware(object): | |
def process_request(self, request, spider): | |
endpoint = os.environ.get('PROXY_ENDPOINT') | |
user = os.environ.get('PROXY_USER') | |
pw = os.environ.get('PROXY_PW') | |
if 'proxy' in request.meta: | |
return | |
request.meta['proxy'] = endpoint | |
proxy_user_pass = '{}:{}'.format(user, pw) | |
encoded_user_pass = base64.encodestring(proxy_user_pass) | |
request.headers['Proxy-Authorization'] = 'Basic ' + encoded_user_pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment