Reputation: 1161
Below is the code that i used. I am using latest python requests. I am getting 407
response from the below request using python 2.7.
And strange thing is i am getting 503 response while using https
instead of http
in the requests.
response = requests.get(query, proxies={'https': "https://username:[email protected]:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
Output: Response [503]
response = requests.get(query, proxies={'http': "http://username:[email protected]:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
Output: Response [407]
But the same code is working on my amazon ec2 instance. Though i am trying to run in local machine.
import urllib2
import urllib
import portalocker
import cookielib
import requests
query = 'http://google.com/search?q=wtf&num=100&tbs=cdr:1,cd_min:2000,cd_max:2015&start=0&filter=0'
headers = {'user-agent': 'Mozilla/5.0 (X11; Linux; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Midori/0.4'}
response = requests.get(query, proxies={'http': "http://username:[email protected]:80"}, headers=headers, timeout=30, allow_redirects=True)
print response
Upvotes: 3
Views: 10763
Reputation: 61
from requests.auth import HTTPProxyAuth
proxyDict = {
'http' : '77.75.105.165',
'https' : '77.75.105.165'
}
auth = HTTPProxyAuth('username', 'mypassword')
r = requests.get("http://www.google.com", proxies=proxyDict, auth=auth)
Upvotes: 5
Reputation: 28405
The status codes might give a clue:
407 Proxy Authentication Required
503 Service Unavailable
These suggest that your proxy isn't running for https and the username/password combination is wrong for the proxy that you are using. Note that it is very unlikely that your local machine needs the same proxy as your the ec2 instance.
Upvotes: -1