【问题标题】:Django - Tastypie POST (update) causing 409 CONFLICTDjango - Tastypie POST(更新)导致 409 CONFLICT
【发布时间】:2012-11-14 20:49:24
【问题描述】:

我正在执行一项需要与 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 到以下 URL:

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 密钥等

【问题讨论】:

    标签: python django post tastypie


    【解决方案1】:

    我想我应该来提供一个“答案”。

    事实证明,分配文件中的内容具有误导性,我不打算通过 POST 更新帐户,因为不允许使用此功能。

    他们真正想要的是让我删除该帐户,然后重新发布它,这似乎不是最好的方法,因为每次“更新”都需要两次 API 调用,而不仅仅是一次。甚至无法使用 PATCH 命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2013-08-03
      • 2021-04-13
      • 2013-01-03
      相关资源
      最近更新 更多