Django - Tastypie POST(更新)导致409 CONFLICT

时间:2012-11-14 20:49:24

标签: python django post tastypie

我正在进行一项任务,我需要与Tastypie API进行交互。我无法控制API,我刚刚得到了它的详细信息,并告诉它设置为仅允许GET,POST和DELETE。

示例POST - 工作

curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X     POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":1,"ip_address":"192.168.1.23"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

示例GET - 工作

curl http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

获得回应:

{"birth_date": null, "city": "", "country": "nl", "email": "test@someemail.com", "first_name": "", "gender": "", "last_name": "", "lead": true, "mailing_lists": [{"name": "Classic NL", "resource_uri": "/v1/mailing_list/1/"}], "phone": "", "resource_uri": "/v1/account/202126/", "street_number": "", "tr_input_method": "", "tr_ip_address": "192.168.1.23", "tr_language": "", "tr_referral": {"name": "SomeFeed", "resource_uri": ""}, "utm_campaign": "", "utm_medium": "", "utm_source": "SomeFeed", "zipcode": ""}

现在,这是我尝试过的许多POST中的一个,以便触发记录的更新:

curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":2,"ip_address":"192.168.1.46"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

结果是:

HTTP/1.1 409 CONFLICT
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:42:35 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive

Email address test@someemail.com already exists.

我也尝试过POST到以下网址:

http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

返回:

HTTP/1.1 501 NOT IMPLEMENTED
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:45:01 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive

我需要使用POST更新记录。我做错了什么?

请注意,我更改了一些数据,例如URL,api密钥等

1 个答案:

答案 0 :(得分:2)

我以为我应该为此提供一个“答案”。

事实证明,在转让文件中写的内容具有误导性,我不会通过POST更新帐户,因为不允许使用此功能。

他们真正想要的是我删除帐户然后重新发布它似乎不是最好的方式,因为它需要两个API调用每个“更新”而不是一个。甚至无法使用PATCH命令。<​​/ p>