在pythoneve应用程序中执行PUT,PATCH返回时,请求的URL不允许使用该方法

2024-09-27 21:33:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用pythoneve编写的web服务。我正在尝试对已创建的资源执行PUT请求。我已经在我的settings.py文件中将item_methods定义为PATCH,但是当我进行调用时,得到了以下响应:

{
  "_status": "ERR",
  "_error": {
      "message": "The method is not allowed for the requested URL.",
      "code": 405
  }
}

在请求有效负载和我要点击的URL之后

网址:-http://127.0.0.1:5000/puburl/

请求有效载荷:-

^{pr2}$

我的settings.py文件如下:

__author__ = 'sappal'

# pulling DBSchema from DBTableSchema
from DBSchema.DBTableSchema import DBTableSchema
from Configs import Configs

dbtableSchema = DBTableSchema()


# Let's just use the local mongod instance. Edit as needed.
# Please note that MONGO_HOST and MONGO_PORT could very well be left
# out as they already default to a bare bones local 'mongod' instance.
## LOCALHOST ENTRIES
MONGO_HOST = Configs.MONGO_DB_HOST
MONGO_PORT = Configs.MONGO_DB_PORT
MONGO_USERNAME = Configs.MONGO_DB_USER_NAME
MONGO_PASSWORD = Configs.MONGO_DB_PASSWORD
MONGO_DBNAME = Configs.MONGO_DB

# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide
# read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']

# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
# individual items  (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PATCH', 'DELETE']

# Used for implementing user-resource restricted access.
# Returns the documents which are associated with particular user
AUTH_FIELD = 'userid'

people = {
  'item_title': 'person',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people,
  'public_methods': ['POST']
}

org = {
  'item_title': 'org',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_org
}

puburl = {
  'item_title': 'puburl',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'item_methods': ['PATCH', 'PUT'],
  'schema': dbtableSchema.schema_people_pub_url
}

address = {
  'item_title': 'address',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_address
}

contactnumber = {
  'item_title': 'contactnumber',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_contact_number
}

template = {
  'item_title': 'template',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_template
}

usersharedcontacts = {
  'item_title': 'usersharedcontacts',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_with_user_shared_contacts
}

cardholder = {
  'item_title': 'cardholder',
  'cache_control': 'max-age=10,must-revalidate',
  'cache_expires': 10,
  'resource_methods': ['GET', 'POST'],
  'schema': dbtableSchema.schema_people_card_holder
}

DOMAIN = {
  'people': people,
  'org': org,
  'puburl': puburl,
  'address': address,
  'contactnumber': contactnumber,
  'template': template,
  'usersharedcontacts': usersharedcontacts,
  'cardholder': cardholder
}

你知道电话为什么失败了吗。。在


Tags: cacheagegettitleschemamongoitempeople
2条回答

我认为问题是etag必须在头中,子句'If Match'=etag。在

您可以在http://python-eve.org/features.html中查看有关“数据完整性和并发控制”的更多信息

乍一看,我会说您正在访问的URL(http://127.0.0.1:5000/puburl/)看起来像一个资源(集合)端点,而PUT是文档(项)端点。这就是为什么要将它添加到item_methods而不是resource_methods。为了使http://127.0.0.1:5000/puburl/<id>工作,您需要点击类似http://127.0.0.1:5000/puburl/<id>的内容。在

相关问题 更多 >

    热门问题