Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 errors on custom repositories #4885

Closed
3 tasks done
vikigenius opened this issue Dec 11, 2021 · 7 comments
Closed
3 tasks done

403 errors on custom repositories #4885

vikigenius opened this issue Dec 11, 2021 · 7 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@vikigenius
Copy link

vikigenius commented Dec 11, 2021

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • Linux 5.15.7_1:
  • Poetry version 1.1.12:
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

Added a custom repository like this:

[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu113"

So that I can install torch from here

Tried installing to a venv with a clean install of poetry. I am using pyenv to maintain python versions so I do:

pyenv local 3.9.7
poetry env use 3.9.7
poetry install 

And then doing poetry add torch==1.10.0 leads to error

Updating dependencies
Resolving dependencies... (0.5s)

  RepositoryError

  403 Client Error: Forbidden for url: https://download.pytorch.org/whl/cu113/python-lsp-server/

  at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/repositories/legacy_repository.py:393 in _get
      389│             if response.status_code == 404:
      390│                 return
      391│             response.raise_for_status()
      392│         except requests.HTTPError as e:
    → 393│             raise RepositoryError(e)
      394│
      395│         if response.status_code in (401, 403):
      396│             self._log(
      397│                 "Authorization error accessing {url}".format(url=response.url),

If packages are not found in custom repository, why is poetry not falling back to PyPI. This is incredibly frustrating. All these workarounds for installing torch and none of them work because of various issues.

Edit

Changing the custom repo to secondary

[[tool.poetry.source]]
name = "torch"
url = "https://download.pytorch.org/whl/cu113"

and doing poetry add torch --source torch still throws the same error? Why is poetry checking a seoncary repo?

@vikigenius vikigenius added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Dec 11, 2021
@severinsimmler
Copy link

Duplicate of #4902.

@vikigenius
Copy link
Author

@severinsimmler But that issue describes a private repo with authentication, this is a public repository of packages, there should be no authentication needed.

@cyd3r
Copy link

cyd3r commented Jan 17, 2022

A quick and hacky workaround would be to modify your file at ~/.local/share/pypoetry/venv/lib/python3.9/site-packages/poetry/repositories/legacy_repository.py and insert a check against a 403 status code. Right before the error is raised, you can change it to:

try:
    response = self.session.get(url)
    if response.status_code == 404:
        return
    # add these two lines below
    if self.url == "https://download.pytorch.org/whl/cu113" and response.status_code == 403:
        return
    response.raise_for_status()
except requests.HTTPError as e:
    raise RepositoryError(e)

Note that this probably does not solve all your problems though (e.g. you won't be able to install torchvision).

@GuillaumeDesforges
Copy link

GuillaumeDesforges commented Apr 4, 2022

My current workaround was to add in pyproject.toml :

[[tool.poetry.source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu113"
secondary = true

and then I can do

$ poetry add torch==1.11.0+cu113

but if I need something from pypi I need to do

$ poetry add python-dotenv --source pypi

EDIT: did not work for requests

@ralbertazzi
Copy link
Contributor

This will be solved in the next 1.5 release with the introduction of explicit repositories, that allow invoking a repository only for dependencies that explicitly require it. As the initial request came from PyTorch, I suggest you have a look at #6409 (comment) (and the whole thread in general).

@radoering I suggest closing this issue

@radoering
Copy link
Member

Closing since all described issues should be resolved in Poetry 1.5. There will be explicit and supplemental package sources, which should do what was expected from secondary here.

Further, as it seems Poetry does not raise an error on 403 anymore for some time now:

try:
response: requests.Response = self.session.get(
url, raise_for_status=False, timeout=REQUESTS_TIMEOUT
)
if response.status_code in (401, 403):
self._log(
f"Authorization error accessing {url}",
level="warning",
)
return None
if response.status_code == 404:
return None
response.raise_for_status()
except requests.exceptions.HTTPError as e:
raise RepositoryError(e)

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants