首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自python的docker-registry PUT请求响应为400,但是Curl运行良好

来自python的docker-registry PUT请求响应为400,但是Curl运行良好
EN

Stack Overflow用户
提问于 2021-07-23 00:27:07
回答 1查看 37关注 0票数 0

我正在尝试从我的私有注册表中GET一个清单v2,并在不同的标签下对其进行PUT。我是用Python语言写的实用程序(requests库)来做的。

如果我将所需图像清单保存到JSON文件中,然后执行curl命令:

代码语言:javascript
复制
curl -XPUT 'http://localhost:5000/v2/<repository>/manifests/latest' -H 'content-type: application/vnd.docker.distribution.manifest.v2+json' -d @manifest.json

它的工作和响应速度为2xx。但是如果我尝试用Python来做这件事:

代码语言:javascript
复制
manifest = requests.get(url='http://localhost:5000/v2/%s/manifests/%s' % (img, tag), 
                        headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'})
put_latest = requests.put(url='http://localhost:5000/v2/%s/manifests/latest' % image, 
                          headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'}, 
                          data=manifest.text)

它只是使用400 Bad Request{'errors': [{'code': 'MANIFEST_INVALID', 'message': 'manifest invalid', 'detail': {}}]}进行响应,而在docker-registry日志中显示为err.detail="missing signature key"

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2021-07-23 03:41:12

我发送了错误的标题键。我想我应该使用Content-Type而不是用于GETAccept

代码语言:javascript
复制
manifest = requests.get(url='http://localhost:5000/v2/%s/manifests/%s' % (img, tag), 
                        headers={'Accept': 'application/vnd.docker.distribution.manifest.v2+json'})
put_latest = requests.put(url='http://localhost:5000/v2/%s/manifests/latest' % image, 
                          headers={'Content-Type': 'application/vnd.docker.distribution.manifest.v2+json'}, 
                          data=manifest.text)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68488419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档