大摇大摆:python请求:javax.ws.rs.NotAllowedException:不允许的HTTP 405方法

时间:2019-02-16 01:29:19

标签: python python-requests swagger-ui hortonworks-dataflow

对于该错误是否多余,我深表歉意,但我正在寻找具体的解决方案。

我正在尝试使用摇摇欲坠的rest API将新版本的架构发布到Hortonworks Schema Registry。我正在使用python请求模块以编程方式发布新版本。

path = '/' + schemaname + '/versions' + '/' + str(max(versions)+1)
logger.info(self.url(path))
requests.post(self.url(path), schemaText)


ERROR  [2019-02-15 17:18:13.496] [dw-167124 - PUT /api/v1/schemaregistry/schemas/diff%20data/versions/2] c.h.r.c.GenericExceptionMapper -  Got exception: [NotAllowedException] / message [HTTP 405 Method Not Allowed] 

我尝试了前面关于“方法允许的异常”的问题所建议的各种方法,例如改用PUT,POST或GET。但是没有一个有效。以编程方式使用其余api将新版本的架构发布到hdf注册表的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

在源代码中,它是@POST @Path("/schemas/{name}/versions")

您需要在最后删除版本号,因为它会返回一个版本。您没有为架构提供特定版本

我不知道是否允许使用空格,因此您可能希望将其从diff data删除

您用于@GET @Path("/schemas/{name}/versions/{version}")的地址不允许其他HTTP方法


参考-https://github.com/hortonworks/registry/blob/HDF-2.1.0.0/schema-registry/rest-service/src/main/java/com/hortonworks/registries/schemaregistry/webservice/SchemaRegistryResource.java#L219

注意:您可以使用swagger-codegen为服务器创建Python代码,而不用在requests中重写代码