diff --git a/poetry/publishing/uploader.py b/poetry/publishing/uploader.py index a7c1383264b..5d8c2709e9e 100644 --- a/poetry/publishing/uploader.py +++ b/poetry/publishing/uploader.py @@ -207,23 +207,6 @@ def post_data(self, file: Path) -> Dict[str, Any]: def _upload( self, session: requests.Session, url: str, dry_run: Optional[bool] = False - ) -> None: - try: - self._do_upload(session, url, dry_run) - except HTTPError as e: - if ( - e.response.status_code == 400 - and "was ever registered" in e.response.text - ): - try: - self._register(session, url) - except HTTPError as e: - raise UploadError(e) - - raise UploadError(e) - - def _do_upload( - self, session: requests.Session, url: str, dry_run: Optional[bool] = False ) -> None: for file in self.files: if not file.is_file(): @@ -231,10 +214,7 @@ def _do_upload( "Wheel or Tar files associated with the Project Package do not exist" ) - resp = self._upload_file(session, url, file, dry_run) - - if not dry_run: - resp.raise_for_status() + self._upload_file(session, url, file, dry_run) def _upload_file( self, @@ -242,7 +222,7 @@ def _upload_file( url: str, file: Path, dry_run: Optional[bool] = False, - ) -> requests.Response: + ) -> None: from cleo.ui.progress_bar import ProgressBar data = self.post_data(file) @@ -293,6 +273,11 @@ def _upload_file( "Redirects are not supported. " "Is the URL missing a trailing slash?" ) + elif resp.status_code == 400 and "was ever registered" in resp.text: + self._register(session, url) + resp.raise_for_status() + else: + resp.raise_for_status() except (requests.ConnectionError, requests.HTTPError) as e: if self._io.output.is_decorated(): self._io.overwrite( @@ -302,8 +287,6 @@ def _upload_file( finally: self._io.write_line("") - return resp - def _register(self, session: requests.Session, url: str) -> requests.Response: """ Register a package to a repository.