Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/Json—两个转储之间的差异,一个将发布到RESTAPI,另一个将提供400_Python_Json_Rest - Fatal编程技术网

Python/Json—两个转储之间的差异,一个将发布到RESTAPI,另一个将提供400

Python/Json—两个转储之间的差异,一个将发布到RESTAPI,另一个将提供400,python,json,rest,Python,Json,Rest,我正在发布到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":

我正在发布到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",  # comma here
        "Content": "testing"    # without comma here
}

为了使其成为有效的JSON字符串,这两个字符串不相同,因为在您的
n
中,您的“HTML”后面没有逗号

这完全改变了它的上下文,使它无效。它必须是:

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

为了使修复此测试的JSON字符串有效,但是主功能和问题失败了,我在这里打开了另一个问题来修复此测试,但是主功能和问题失败了,我在这里打开了另一个问题