Repository: pypa/pipenv
Issue: Public dependencies are not resolved properly on private packages

When a public package is listed as a dependency in a private package, the package will fail to install because it doesn't exist in the private index.

For example, if you specify an additional source in your `Pipfile`:

```
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[[source]]

url = "http://localhost:8080/"
name = "local"
```

This is the following output from running `pipenv install --verbose local_package`

```
Installing local_package…
⠋Installing u'local_package'
$ "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/bin/pip" install   --verbose    "local_package" -i https://pypi.python.org/simple --exists-action w
⠏$ "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/bin/pip" install   --verbose    "local_package" -i http://localhost:8080/ --exists-action w
Collecting local_package
  1 location(s) to search for versions of local-package:
  * http://localhost:8080/local-package/
  Getting page http://localhost:8080/local-package/
  Starting new HTTP connection (1): localhost
  "GET /local-package/ HTTP/1.1" 200 None
  Analyzing links from page http://localhost:8080/local-package/
    Found link http://localhost:8080/local-package/local_package-0.1.1-py3-none-any.whl#md5=ce978ae83f1fec0526e7f34c45d27810 (from http://localhost:8080/local-package/), version: 0.1.1
  Using version 0.1.1 (newest of versions: 0.1.1)
  "GET /local-package/local_package-0.1.1-py3-none-any.whl HTTP/1.1" 200 7273
  Downloading http://localhost:8080/local-package/local_package-0.1.1-py3-none-any.whl
  Downloading from URL http://localhost:8080/local-package/local_package-0.1.1-py3-none-any.whl#md5=ce978ae83f1fec0526e7f34c45d27810 (from http://localhost:8080/local-package/)
Collecting boto3 (from local_package)
  1 location(s) to search for versions of boto3:
  * http://localhost:8080/boto3/
  Getting page http://localhost:8080/boto3/
  "GET /boto3/ HTTP/1.1" 403 None
  Could not fetch URL http://localhost:8080/boto3/: 403 Client Error: Forbidden for url: http://localhost:8080/boto3/ - skipping
Cleaning up...
Exception information:
Traceback (most recent call last):
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/commands/install.py", line 335, in run
    wb.build(autobuilding=True)
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/Users/guido/.local/share/virtualenvs/src-GqcYiTnw/lib/python3.6/site-packages/pip/index.py", line 514, in find_requirement
    'No matching distribution found for %s' % req
pip.exceptions.DistributionNotFound: No matching distribution found for boto3 (from local_package)

Error:  An error occurred while installing local_package!
  Could not find a version that satisfies the requirement boto3 (from local_package) (from versions: )
No matching distribution found for boto3 (from local_package)
```

It seems that the issue is with pipenv using `-i` instead of `--extra-index-url`

If I run `pip install --extra-index-url http://localhost:8080 local_package` everything is installed correctly.

Specifying the `index` for `local_package` under `[packages]` doesn't help.

##### Describe your environment

1. OS Type: macOS Sierra
1. Python version: Python 3.6.3
1. Pipenv version: pipenv, version 10.1.2

##### Expected result

I would expect for the public package (in the case above, `boto3`), to be fetched from the public source by default.

##### Actual result

The public package is fetched from the private source.

##### Steps to replicate

Set up a private pypi index, add source to Pipfile, and run install command from above.


Changed files:
pipenv/patched/notpip/index.py, pipenv/utils.py

diff --git a/pipenv/patched/notpip/index.py b/pipenv/patched/notpip/index.py
index 13150428..fdf2cd52 100644
--- a/pipenv/patched/notpip/index.py
+++ b/pipenv/patched/notpip/index.py
@@ -34,7 +34,7 @@ from notpip._vendor import html5lib, requests, six
 from pip9._vendor.packaging.version import parse as parse_version
 from pip9._vendor.packaging.utils import canonicalize_name
 from notpip._vendor.packaging import specifiers
-from pip9._vendor.requests.exceptions import SSLError
+from pip9._vendor.requests.exceptions import SSLError, HTTPError
 from pip9._vendor.distlib.compat import unescape
 
 
@@ -602,7 +602,10 @@ class PackageFinder(object):
                 continue
             seen.add(location)
 
-            page = self._get_page(location)
+            try:
+                page = self._get_page(location)
+            except HTTPError as e:
+                page = None
             if page is None:
                 continue
 
diff --git a/pipenv/utils.py b/pipenv/utils.py
index 3e6c2926..322b327b 100644
--- a/pipenv/utils.py
+++ b/pipenv/utils.py
@@ -619,9 +619,15 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
                 specs = ''
 
         if include_index:
+            pip_src_args = []
             if 'index' in deps[dep]:
-                pip_args = prepare_pip_source_args([project.get_source(deps[dep]['index'])])
-                index = ' '.join(pip_args)
+                dep_src = [project.get_source(deps[dep]['index'])]
+                extra_indexes = [src for src in project.sources if src != dep_src]
+                pip_src_args = dep_src + extra_indexes
+            else:
+                pip_src_args = project.sources
+            pip_args = prepare_pip_source_args(pip_src_args)
+            index = ' '.join(pip_args)
 
         # Support for version control
         maybe_vcs = [vcs for vcs in VCS_LIST if vcs in deps[dep]]