使用Python的requests库测试github API时遇到的问题




def json_post():
    # response = requests.post(build_uri("user/emails"), auth=("[email protected]", "XXXXXXXXXX"),
    #                          json=["[email protected]"])
    response = requests.delete(build_uri("user/emails"),
                               auth=("[email protected]", "XXXXXXXXXX"),
                               json=["[email protected]"])
    print better_print(response.text)
    print response.request.headers
    print response.request.body
    print response.status_code, response.reason


{
    "documentation_url": "https://developer.github.com/v3/users/emails/#delete-email-addresses", 
    "message": "Not Found"
}
{'Content-Length': '16', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Basic ZG9uZ3lhMjAwODIyNTAxMjNAMTYzLmNvbTp3ZHk4OTE5NDc2ODAw'}
["[email protected]"]
404 Not Found




def json_post():
    response = requests.post(build_uri("user/emails"), auth=("[email protected]", "XXXXXXXXXX"),
                             json=["[email protected]"])
    # response = requests.delete(build_uri("user/emails"),
    #                            auth=("[email protected]", "XXXXXXXXXX"),
    #                           json=["[email protected]"])
    print better_print(response.text)
    print response.request.headers
    print response.request.body
    print response.status_code, response.reason


    [
    {
        "verified": true, 
        "email": "[email protected]", 
        "visibility": "public", 
        "primary": true
    }, 
    {
        "verified": true, 
        "email": "[email protected]", 
        "visibility": null, 
        "primary": false
    }, 
    {
        "verified": false, 
        "email": "[email protected]", 
        "visibility": null, 
        "primary": false
    }
]
{'Content-Length': '16', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Basic XXXXXXXXXX'}
["[email protected]"]

201 Created

我首先使用第二段代码在github账号下,添加了一个邮箱[email protected]

从运行的结果可以看出,邮箱成功的添加到账号下,status_code 是201,即已经创建


然后我使用第一段代码去删除这个新添加的邮箱,但是却显示404 not found

我自己的查看了API的文档,目前没有找出什么原因,故记录在此,也希望有缘人看到了能给一些建议;






你可能感兴趣的:(python)