Search code examples
pythonweb-servicespython-2.7flaskeve

Performing PUT , PATCH in python eve application returns , The method is not allowed for the requested URL


I have a written web-services using the Python Eve . I am trying to perform a PUT request on the resource that is already been created . I have defined the item_methods as PATCH in my settings.py file , but I am getting the following Response when I am making the call :-

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

Following the Request Payload and the URL on which I am hitting

URL :- http://127.0.0.1:5000/puburl/

Request Payload :-

[
 {
  "puburl": "https://github.com/tushar",
  "userid": "xFGellL",
  "_etag": "714df986e0bf802962a6b8cb4b9b1513e1709d7b"
 }
]

My settings.py file is as follows :-

__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
}

Any ideas why the call is failing ..


Solution

  • At first glance, I would say that the URL you are hitting (http://127.0.0.1:5000/puburl/) looks like a resource (collection) endpoint while PUT is a document (item) endpoint. That's why you are adding it to item_methods and not to resource_methods. You want to hit something like http://127.0.0.1:5000/puburl/<id> in order for PUT to work.