Skip to content

Commit eb8fed4

Browse files
committed
support empty password for http_proxy config
1 parent 38e5bfb commit eb8fed4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

scrapy/downloadermiddlewares/httpproxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _get_proxy(self, url, orig_type):
2525
proxy_type, user, password, hostport = _parse_proxy(url)
2626
proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))
2727

28-
if user and password:
28+
if user:
2929
user_pass = '%s:%s' % (unquote(user), unquote(password))
3030
creds = base64.b64encode(user_pass).strip()
3131
else:

tests/test_downloadermiddleware_httpproxy.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def test_proxy_auth(self):
5454
self.assertEquals(req.meta, {'proxy': 'https://proxy:3128'})
5555
self.assertEquals(req.headers.get('Proxy-Authorization'), 'Basic dXNlcjpwYXNz')
5656

57+
def test_proxy_auth_empty_passwd(self):
58+
os.environ['http_proxy'] = 'https://user:@proxy:3128'
59+
mw = HttpProxyMiddleware()
60+
req = Request('http://scrapytest.org')
61+
assert mw.process_request(req, spider) is None
62+
self.assertEquals(req.meta, {'proxy': 'https://proxy:3128'})
63+
self.assertEquals(req.headers.get('Proxy-Authorization'), 'Basic dXNlcjo=')
64+
5765
def test_proxy_already_seted(self):
5866
os.environ['http_proxy'] = http_proxy = 'https://proxy.for.http:3128'
5967
mw = HttpProxyMiddleware()

0 commit comments

Comments
 (0)