We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
HTTP_PROXY variable with username and empty password not supported
Scrapy doesn't support proxy authentication when the password is empty when using the HTTP_PROXY environment variable to supply the proxy argument.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scrapy/downloadermiddlewares/httpproxy.py`
Content:
```
1 import base64
2 from six.moves.urllib.request import getproxies, proxy_bypass
3 from six.moves.urllib.parse import unquote
4 try:
5     from urllib2 import _parse_proxy
6 except ImportError:
7     from urllib.request import _parse_proxy
8 from six.moves.urllib.parse import urlunparse
9 
10 from scrapy.utils.httpobj import urlparse_cached
11 from scrapy.exceptions import NotConfigured
12 
13 
14 class HttpProxyMiddleware(object):
15 
16     def __init__(self):
17         self.proxies = {}
18         for type, url in getproxies().items():
19             self.proxies[type] = self._get_proxy(url, type)
20 
21         if not self.proxies:
22             raise NotConfigured
23 
24     def _get_proxy(self, url, orig_type):
25         proxy_type, user, password, hostport = _parse_proxy(url)
26         proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))
27 
28         if user and password:
29             user_pass = '%s:%s' % (unquote(user), unquote(password))
30             creds = base64.b64encode(user_pass).strip()
31         else:
32             creds = None
33 
34         return creds, proxy_url
35 
36     def process_request(self, request, spider):
37         # ignore if proxy is already seted
38         if 'proxy' in request.meta:
39             return
40 
41         parsed = urlparse_cached(request)
42         scheme = parsed.scheme
43 
44         # 'no_proxy' is only supported by http schemes
45         if scheme in ('http', 'https') and proxy_bypass(parsed.hostname):
46             return
47 
48         if scheme in self.proxies:
49             self._set_proxy(request, scheme)
50 
51     def _set_proxy(self, request, scheme):
52         creds, proxy = self.proxies[scheme]
53         request.meta['proxy'] = proxy
54         if creds:
55             request.headers['Proxy-Authorization'] = 'Basic ' + creds
56
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scrapy/downloadermiddlewares/httpproxy.py b/scrapy/downloadermiddlewares/httpproxy.py
--- a/scrapy/downloadermiddlewares/httpproxy.py
+++ b/scrapy/downloadermiddlewares/httpproxy.py
@@ -25,7 +25,7 @@
         proxy_type, user, password, hostport = _parse_proxy(url)
         proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))
 
-        if user and password:
+        if user:
             user_pass = '%s:%s' % (unquote(user), unquote(password))
             creds = base64.b64encode(user_pass).strip()
         else:

{"golden_diff": "diff --git a/scrapy/downloadermiddlewares/httpproxy.py b/scrapy/downloadermiddlewares/httpproxy.py\n--- a/scrapy/downloadermiddlewares/httpproxy.py\n+++ b/scrapy/downloadermiddlewares/httpproxy.py\n@@ -25,7 +25,7 @@\n         proxy_type, user, password, hostport = _parse_proxy(url)\n         proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))\n \n-        if user and password:\n+        if user:\n             user_pass = '%s:%s' % (unquote(user), unquote(password))\n             creds = base64.b64encode(user_pass).strip()\n         else:\n", "issue": "HTTP_PROXY variable with username and empty password not supported\nScrapy doesn't support proxy authentication when the password is empty when using the HTTP_PROXY environment variable to supply the proxy argument.\n\n", "before_files": [{"content": "import base64\nfrom six.moves.urllib.request import getproxies, proxy_bypass\nfrom six.moves.urllib.parse import unquote\ntry:\n    from urllib2 import _parse_proxy\nexcept ImportError:\n    from urllib.request import _parse_proxy\nfrom six.moves.urllib.parse import urlunparse\n\nfrom scrapy.utils.httpobj import urlparse_cached\nfrom scrapy.exceptions import NotConfigured\n\n\nclass HttpProxyMiddleware(object):\n\n    def __init__(self):\n        self.proxies = {}\n        for type, url in getproxies().items():\n            self.proxies[type] = self._get_proxy(url, type)\n\n        if not self.proxies:\n            raise NotConfigured\n\n    def _get_proxy(self, url, orig_type):\n        proxy_type, user, password, hostport = _parse_proxy(url)\n        proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))\n\n        if user and password:\n            user_pass = '%s:%s' % (unquote(user), unquote(password))\n            creds = base64.b64encode(user_pass).strip()\n        else:\n            creds = None\n\n        return creds, proxy_url\n\n    def process_request(self, request, spider):\n        # ignore if proxy is already seted\n        if 'proxy' in request.meta:\n            return\n\n        parsed = urlparse_cached(request)\n        scheme = parsed.scheme\n\n        # 'no_proxy' is only supported by http schemes\n        if scheme in ('http', 'https') and proxy_bypass(parsed.hostname):\n            return\n\n        if scheme in self.proxies:\n            self._set_proxy(request, scheme)\n\n    def _set_proxy(self, request, scheme):\n        creds, proxy = self.proxies[scheme]\n        request.meta['proxy'] = proxy\n        if creds:\n            request.headers['Proxy-Authorization'] = 'Basic ' + creds\n", "path": "scrapy/downloadermiddlewares/httpproxy.py"}], "after_files": [{"content": "import base64\nfrom six.moves.urllib.request import getproxies, proxy_bypass\nfrom six.moves.urllib.parse import unquote\ntry:\n    from urllib2 import _parse_proxy\nexcept ImportError:\n    from urllib.request import _parse_proxy\nfrom six.moves.urllib.parse import urlunparse\n\nfrom scrapy.utils.httpobj import urlparse_cached\nfrom scrapy.exceptions import NotConfigured\n\n\nclass HttpProxyMiddleware(object):\n\n    def __init__(self):\n        self.proxies = {}\n        for type, url in getproxies().items():\n            self.proxies[type] = self._get_proxy(url, type)\n\n        if not self.proxies:\n            raise NotConfigured\n\n    def _get_proxy(self, url, orig_type):\n        proxy_type, user, password, hostport = _parse_proxy(url)\n        proxy_url = urlunparse((proxy_type or orig_type, hostport, '', '', '', ''))\n\n        if user:\n            user_pass = '%s:%s' % (unquote(user), unquote(password))\n            creds = base64.b64encode(user_pass).strip()\n        else:\n            creds = None\n\n        return creds, proxy_url\n\n    def process_request(self, request, spider):\n        # ignore if proxy is already seted\n        if 'proxy' in request.meta:\n            return\n\n        parsed = urlparse_cached(request)\n        scheme = parsed.scheme\n\n        # 'no_proxy' is only supported by http schemes\n        if scheme in ('http', 'https') and proxy_bypass(parsed.hostname):\n            return\n\n        if scheme in self.proxies:\n            self._set_proxy(request, scheme)\n\n    def _set_proxy(self, request, scheme):\n        creds, proxy = self.proxies[scheme]\n        request.meta['proxy'] = proxy\n        if creds:\n            request.headers['Proxy-Authorization'] = 'Basic ' + creds\n", "path": "scrapy/downloadermiddlewares/httpproxy.py"}]}