List User Messages:列出用户消息

List User Messages:列出用户消息:


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://127.0.0.1:8000/api2/user/msgs/2/"



curl -d "message=this is a user msg reply from Scan" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/user/msgs/015208@zjtlcb.com/"



[root@node0H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/user/msgs/015208@zjtlcb.com/"
{"to_email": "015208@zjtlcb.com", "next_page": -1, "msgs": [{"attachments": [], "timestamp": 1503313050, "from_email": "99999@zjtlcb.com", "msgid": 3, "msg": "this is a user msg reply from Scan", "nickname": "99999"}, {"attachments": [], "timestamp": 1503313045, "from_email": "99999@zjtlcb.com", "msgid": 2, "msg": "this is a user msg reply from u8d75u6768u5065", "nickname": "99999"}, {"attachments": [], "timestamp": 1503313014, "from_email": "99999@zjtlcb.com", "msgid": 1, "msg": "this is a user msg reply from Scan", "nickname": "99999"}]}[root@node01 ~]# 

def list_user_messages():
    token = gettoken()
    print len(token)
    token = 'Token' + ' ' + token
    print token
    url = 'http://192.168.137.1:8000/api2/user/msgs/015208@zjtlcb.com/'
    conn = httplib.HTTPConnection('127.0.0.1', 8000)
    headers = {"Authorization": token, "Accept": "application/json; indent=10", "content-type": "application/json"}
    print headers
    conn.request('GET', url, '', headers)
    response = conn.getresponse()
    res = response.read()
    print res
if __name__ == '__main__':
    list_user_messages()

C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/a8.py
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}
<type 'str'>
<type 'dict'>
0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
40
Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
{'content-type': 'application/json', 'Accept': 'application/json; indent=10', 'Authorization': u'Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7'}
{
        "to_email": "015208@zjtlcb.com",
        "next_page": -1,
        "msgs": [
                {
                        "attachments": [],
                        "timestamp": 1503313050,
                        "from_email": "99999@zjtlcb.com",
                        "msgid": 3,
                        "msg": "this is a user msg reply from Scan",
                        "nickname": "99999"
                },
                {
                        "attachments": [],
                        "timestamp": 1503313045,
                        "from_email": "99999@zjtlcb.com",
                        "msgid": 2,
                        "msg": "this is a user msg reply from u8d75u6768u5065",
                        "nickname": "99999"
                },
                {
                        "attachments": [],
                        "timestamp": 1503313014,
                        "from_email": "99999@zjtlcb.com",
                        "msgid": 1,
                        "msg": "this is a user msg reply from Scan",
                        "nickname": "99999"
                }
        ]
}

Process finished with exit code 0

原文地址:https://www.cnblogs.com/hzcya1995/p/13349576.html