将包从 Azure Devops 发布到 PyPi 在 twine 上传时挂起
Publishing package to PyPi from Azure Devops hangs at twine upload
我想从我们的 Azure Devops 发布管道将构建的 .whl 包发布到 PyPi.org,但脚本 twine upload
一直挂起,没有错误、完成或超时。所以实际上传我们的包(特别小)是不行的。
这是它的设置方式:
yaml 构建:
trigger:
- master
pr: none
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
addToPath: true
architecture: 'x64'
- script: python -m pip install --upgrade pip setuptools wheel
displayName: 'Install tools'
- script: pip install -r src/requirements.txt
displayName: 'Install requirements'
- script: |
python src/setup.py bdist_wheel
displayName: 'Artifact creation'
- script: python -m pip install --upgrade twine
displayName: 'Install Twine'
- task: TwineAuthenticate@1
inputs:
pythonUploadServiceConnection: 'AzureML PyPi feed'
- script: |
python -m twine upload --config-file $(PYPIRC_PATH) dist/*.whl
displayName: 'Publish to PyPi through Twine'
服务连接:
- 验证方法由
Authentication Token
指定。
- Python 存储库 url 上传:
https://upload.pypi.org/legacy
- 端点名称:
azure-pypi
- 服务连接名称:
AzureML PyPi feed
- [X] 授予对所有管道的访问权限
发布日志(最相关的部分):
TwineAuthenticate 步骤:
Starting: TwineAuthenticate
==============================================================================
Task : Python twine upload authenticate
Description : Authenticate for uploading Python distributions using twine. Add '-r FeedName/EndpointName --config-file $(PYPIRC_PATH)' to your twine upload command. For feeds present in this organization, use the feed name as the repository (-r). Otherwise, use the endpoint name defined in the service connection.
Version : 1.165.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/twine-authenticate
==============================================================================
75c64e89-xxxxxredactedxxxxx exists true
Adding authentication to configuration for registry azure-pypi
Successfully added auth for 0 internal feed and 1 external endpoint.
Finishing: TwineAuthenticate
发布步骤:
Starting: Publish to PyPi through Twine
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.164.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
python -m twine upload --config-file /home/vsts/work/_temp/twineAuthenticate/Wv8nMR/.pypirc dist/*.whl
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/0d772e31-148f-4e3c-999b-b2a43a02b287.sh
Uploading distributions to https://upload.pypi.org/legacy/
这在 30 多分钟内保持不变,所以我在没有部署包的情况下取消我的发布。对此有什么想法吗?
我现在有一个临时解决方法:
我跳过了配置文件的使用,而是执行了以下代码:
- script: |
python -m twine upload --skip-existing --verbose -p $(pypi-api-token) -u __token__ --repository $(pypi-project-name) --repository-url https://upload.pypi.org/legacy/ dist/*.whl
displayName: 'Publish to PyPi through Twine'
在那里,我注意到了更多(更好的)异常日志记录,它指出了两点:
- 我用于我的配置文件的令牌被设置为一个项目范围,其名称与我在服务连接中指定的项目不同
- 存储库 url 确实必须以尾部正斜杠结尾,否则会出现 RedirectDetected 异常。
基于上述发现,我将我的 yaml 片段更新为以下内容:
- script: |
python -m twine upload --skip-existing --verbose --repository $(pypi-project-name) --config-file $(PYPIRC_PATH) dist/*.whl
displayName: 'Publish to PyPi through Twine'
但是在执行此操作时,我现在在构建中收到以下异常消息:
Generating script.
Script contents:
python -m twine upload --skip-existing --verbose --repository arcus-azureml --config-file /home/vsts/work/_temp/twineAuthenticate/2QGKVH/.pypirc dist/*.whl
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/7605dac9-5fa9-4856-94af-e938018278a5.sh
Uploading distributions to https://upload.pypi.org/legacy/
Uploading arcus_azureml-0.0.2-py3-none-any.whl
0%| | 0.00/5.80k [00:00<?, ?B/s]
100%|██████████| 5.80k/5.80k [00:00<00:00, 52.4kB/s]HTTPError: 403 Client Error: Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details for url: https://upload.pypi.org/legacy/
Content received from server:
<html>
<head>
<title>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details</title>
</head>
<body>
<h1>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details</h1>
Access was denied to this resource.<br/><br/>
Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details
我也输出了pypirc文件的内容,使用CAT命令,文件内容是这样的:
[distutils]
index-servers=arcus-azureml
[arcus-azureml]
repository=https://upload.pypi.org/legacy/
username=build
password=***
更新解决方案
因此,安排 403 的修复方法是更改我的服务连接以使用 'Username and Password' 作为身份验证方法,而不是使用以下设置的身份验证令牌:
- 用户名:
__token__
- 密码:实际的api令牌作为密码
执行此操作后,一切都按照我想要的方式进行。
我想从我们的 Azure Devops 发布管道将构建的 .whl 包发布到 PyPi.org,但脚本 twine upload
一直挂起,没有错误、完成或超时。所以实际上传我们的包(特别小)是不行的。
这是它的设置方式:
yaml 构建:
trigger:
- master
pr: none
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
addToPath: true
architecture: 'x64'
- script: python -m pip install --upgrade pip setuptools wheel
displayName: 'Install tools'
- script: pip install -r src/requirements.txt
displayName: 'Install requirements'
- script: |
python src/setup.py bdist_wheel
displayName: 'Artifact creation'
- script: python -m pip install --upgrade twine
displayName: 'Install Twine'
- task: TwineAuthenticate@1
inputs:
pythonUploadServiceConnection: 'AzureML PyPi feed'
- script: |
python -m twine upload --config-file $(PYPIRC_PATH) dist/*.whl
displayName: 'Publish to PyPi through Twine'
服务连接:
- 验证方法由
Authentication Token
指定。 - Python 存储库 url 上传:
https://upload.pypi.org/legacy
- 端点名称:
azure-pypi
- 服务连接名称:
AzureML PyPi feed
- [X] 授予对所有管道的访问权限
发布日志(最相关的部分):
TwineAuthenticate 步骤:
Starting: TwineAuthenticate
==============================================================================
Task : Python twine upload authenticate
Description : Authenticate for uploading Python distributions using twine. Add '-r FeedName/EndpointName --config-file $(PYPIRC_PATH)' to your twine upload command. For feeds present in this organization, use the feed name as the repository (-r). Otherwise, use the endpoint name defined in the service connection.
Version : 1.165.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/twine-authenticate
==============================================================================
75c64e89-xxxxxredactedxxxxx exists true
Adding authentication to configuration for registry azure-pypi
Successfully added auth for 0 internal feed and 1 external endpoint.
Finishing: TwineAuthenticate
发布步骤:
Starting: Publish to PyPi through Twine
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.164.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
python -m twine upload --config-file /home/vsts/work/_temp/twineAuthenticate/Wv8nMR/.pypirc dist/*.whl
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/0d772e31-148f-4e3c-999b-b2a43a02b287.sh
Uploading distributions to https://upload.pypi.org/legacy/
这在 30 多分钟内保持不变,所以我在没有部署包的情况下取消我的发布。对此有什么想法吗?
我现在有一个临时解决方法:
我跳过了配置文件的使用,而是执行了以下代码:
- script: |
python -m twine upload --skip-existing --verbose -p $(pypi-api-token) -u __token__ --repository $(pypi-project-name) --repository-url https://upload.pypi.org/legacy/ dist/*.whl
displayName: 'Publish to PyPi through Twine'
在那里,我注意到了更多(更好的)异常日志记录,它指出了两点:
- 我用于我的配置文件的令牌被设置为一个项目范围,其名称与我在服务连接中指定的项目不同
- 存储库 url 确实必须以尾部正斜杠结尾,否则会出现 RedirectDetected 异常。
基于上述发现,我将我的 yaml 片段更新为以下内容:
- script: |
python -m twine upload --skip-existing --verbose --repository $(pypi-project-name) --config-file $(PYPIRC_PATH) dist/*.whl
displayName: 'Publish to PyPi through Twine'
但是在执行此操作时,我现在在构建中收到以下异常消息:
Generating script.
Script contents:
python -m twine upload --skip-existing --verbose --repository arcus-azureml --config-file /home/vsts/work/_temp/twineAuthenticate/2QGKVH/.pypirc dist/*.whl
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/7605dac9-5fa9-4856-94af-e938018278a5.sh
Uploading distributions to https://upload.pypi.org/legacy/
Uploading arcus_azureml-0.0.2-py3-none-any.whl
0%| | 0.00/5.80k [00:00<?, ?B/s]
100%|██████████| 5.80k/5.80k [00:00<00:00, 52.4kB/s]HTTPError: 403 Client Error: Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details for url: https://upload.pypi.org/legacy/
Content received from server:
<html>
<head>
<title>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details</title>
</head>
<body>
<h1>403 Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details</h1>
Access was denied to this resource.<br/><br/>
Invalid or non-existent authentication information. See https://pypi.org/help/#invalid-auth for details
我也输出了pypirc文件的内容,使用CAT命令,文件内容是这样的:
[distutils]
index-servers=arcus-azureml
[arcus-azureml]
repository=https://upload.pypi.org/legacy/
username=build
password=***
更新解决方案
因此,安排 403 的修复方法是更改我的服务连接以使用 'Username and Password' 作为身份验证方法,而不是使用以下设置的身份验证令牌:
- 用户名:
__token__
- 密码:实际的api令牌作为密码
执行此操作后,一切都按照我想要的方式进行。