Python/json-两个垃圾场之间的差异,一个将发布到REST API,另一个将给出400



我要发布到Office 365 REST API,并按照下面的形式创建转储:

def CreateEvent(auth, cal_id,  subject, start_time, end_time, attendees, content):
    create_url = 'https://outlook.office365.com/api/v1.0/me/calendars/{0}/events'.format(cal_id)
    headers = {"Content-type": "application/json", "Accept": "application/json"}
    data = {"Subject":"","Attendees": [],"End": {},"Start": {},"Body": {}}
    data["Subject"] = subject
    data["StartTimeZone"] = "GMT Standard Time"
    data["Start"] = start_time
    data["EndTimeZone"] = "GMT Standard Time"
    data["End"] = end_time
    data["Attendees"] = attendees
    data["Body"]["ContentType"] = "Text"
    data["Body"]["Content"] = content
    content_data = json.dumps(data)
    #return data
    response = requests.post(create_url,data,headers=headers,auth=auth)
    return response

这会产生一个有序的转储,我认为这应该引起任何问题。

我试图逆转工程师,我多次成功测试了我的垃圾场,我的垃圾场都以相同的顺序将它们放在问题上。

基本上,如果我创建帖子并拥有y作为内容,我会得到201,邀请使我成为我的方式,如果我发布了n,我得到了400个。现在对我来说是相同的,但是我开始了几个小时,我能看到的唯一差异是在内容中测试后有一个逗号。但是我将其删除并尝试了,这也失败了

y="""
{
  "Subject": "TESTTTT",
  "Body": {
    "ContentType": "HTML",
    "Content": "I think it will meet our requirements!"
  },
  "Start": "2016-12-02T11:30:00Z",
  "StartTimeZone": "GMT Standard Time",
  "End": "2016-12-02T11:45:00Z",
  "EndTimeZone": "GMT Standard Time",
  "Attendees": [
    {
      "EmailAddress": {
            "Name": "Alex ",
            "Address": "alex@test.com"
      },
      "Type": "Required"
    }
  ]
}
"""
n = """
{
    "Subject": "Maintenance: test",
    "Body": {
        "ContentType": "HTML"
        "Content": "testing",
    },
    "Start": "2016-12-02T02:00:00Z",
    "StartTimeZone": "GMT Standard Time",
    "End": "2016-12-02T06:00:00Z",
    "EndTimeZone": "GMT Standard Time",
    "Attendees": [
        {
            "EmailAddress": {
                "Name": "Alex ",
                "Address": "alex@test.com"
            },
            "Type": "Required"
        }
    ]
}
"""

这些并不完全相同,因为在您的n中,您没有" html"之后的逗号,

"Body": {
        "ContentType": "HTML"
        "Content": "testing",
}

完全改变了其上下文并使其无效JSON。必须是:

"Body": {
        "ContentType": "HTML",  # comma here
        "Content": "testing"    # without comma here
}

为了使其有效JSON String

相关内容

最新更新