|
6 | 6 | from weblib.http import (normalize_url, normalize_post_data, |
7 | 7 | normalize_http_values) |
8 | 8 | from weblib.encoding import make_str, decode_pairs |
9 | | -from urllib3 import PoolManager, ProxyManager, exceptions |
| 9 | +from urllib3 import PoolManager, ProxyManager, exceptions, make_headers |
10 | 10 | from urllib3.filepost import encode_multipart_formdata |
11 | 11 | from urllib3.fields import RequestField |
12 | 12 | from urllib3.util.retry import Retry |
13 | 13 | from urllib3.util.timeout import Timeout |
| 14 | +from urllib3.exceptions import ProxySchemeUnknown |
14 | 15 | import six |
15 | 16 | from six.moves.urllib.parse import urlencode, urlsplit |
16 | 17 | import random |
@@ -78,8 +79,6 @@ def get_full_url(self): |
78 | 79 | return self.url |
79 | 80 |
|
80 | 81 |
|
81 | | - |
82 | | - |
83 | 82 | class Urllib3Transport(BaseTransport): |
84 | 83 | """ |
85 | 84 | Grab network transport based on urllib3 library. |
@@ -219,11 +218,15 @@ def request(self): |
219 | 218 |
|
220 | 219 | if req.proxy: |
221 | 220 | if req.proxy_userpwd: |
222 | | - auth = '%s@' % req.proxy_userpwd |
| 221 | + headers = make_headers(proxy_basic_auth=req.proxy_userpwd) |
223 | 222 | 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) |
227 | 230 | else: |
228 | 231 | pool = self.pool |
229 | 232 | try: |
|
0 commit comments