Skip to content

Commit ea3ade6

Browse files
committed
Merge pull request #166 from rblack/master
urllib3 transport proxy auth fix
2 parents ea95f09 + fff063b commit ea3ade6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

grab/transport/urllib3.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from weblib.http import (normalize_url, normalize_post_data,
77
normalize_http_values)
88
from weblib.encoding import make_str, decode_pairs
9-
from urllib3 import PoolManager, ProxyManager, exceptions
9+
from urllib3 import PoolManager, ProxyManager, exceptions, make_headers
1010
from urllib3.filepost import encode_multipart_formdata
1111
from urllib3.fields import RequestField
1212
from urllib3.util.retry import Retry
1313
from urllib3.util.timeout import Timeout
14+
from urllib3.exceptions import ProxySchemeUnknown
1415
import six
1516
from six.moves.urllib.parse import urlencode, urlsplit
1617
import random
@@ -78,8 +79,6 @@ def get_full_url(self):
7879
return self.url
7980

8081

81-
82-
8382
class Urllib3Transport(BaseTransport):
8483
"""
8584
Grab network transport based on urllib3 library.
@@ -219,11 +218,15 @@ def request(self):
219218

220219
if req.proxy:
221220
if req.proxy_userpwd:
222-
auth = '%s@' % req.proxy_userpwd
221+
headers = make_headers(proxy_basic_auth=req.proxy_userpwd)
223222
else:
224-
auth = ''
225-
proxy_url = '%s://%s%s' % (req.proxy_type, auth, req.proxy)
226-
pool = ProxyManager(proxy_url)
223+
headers = None
224+
proxy_url = '%s://%s' % (req.proxy_type, req.proxy)
225+
try:
226+
pool = ProxyManager(proxy_url, proxy_headers=headers)
227+
except ProxySchemeUnknown:
228+
raise GrabMisuseError('Urllib3 transport does '
229+
'not support %s proxies' % req.proxy_type)
227230
else:
228231
pool = self.pool
229232
try:

0 commit comments

Comments
 (0)