Python Forum

Full Version: get and reuse the token value with huawei modem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,
so i want to read some sms received in my huawei modem.

For that i m tryin to first get the token and session id from the 'http://192.168.8.1/api/webserver/SesTokInfo page

then try to reuse this token in the page http://192.168.8.1/api/sms/sms-list


but i got this error
    <error>
    <code>125002</code>
    <message></message>
    </error>
which mean that i don t have the right token value, what i m wondering about.


so this is how my code looks

import hashlib
import base64
import binascii
import xml.etree.ElementTree as ET
from datetime import datetime
import requests
from bs4 import BeautifulSoup

BASEURL = 'http://192.168.8.1'


session = requests.Session()
reqresponse = session.get(BASEURL + '/api/webserver/SesTokInfo')
if reqresponse.status_code == 200:
        root = ET.fromstring(reqresponse.text)
        for results in root.iter('SesInfo'):
            sessionid = results.text
            print("the sessionId is", sessionid)
        for results in root.iter('TokInfo'):
            token = results.text
            print("The token is", token)
        sessioncookies = reqresponse.cookies

post_data = '<?xml version = "1.0" encoding = "UTF-8"?>\n'
post_data += '<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount><BoxType>1</BoxType><SortTyp$

headers = {'Content-Type': 'text/xml; charset=UTF-8',
               '__RequestVerificationToken': token
              }

api_url = BASEURL + '/api/sms/sms-list'
logonresponse = session.post( api_url, data=post_data, headers=headers, cookies=sessioncookies)
logonresponse2 = session.get( api_url, data=post_data, headers=headers, cookies=sessioncookies)




result = BeautifulSoup(logonresponse.text, 'html.parser')

for r in result:
    print(r)
can someone helo me with the troubleshooting please?
so i want to read some sms received in my huawei modem. for this i have to take a token value from one page and reuse it in another pages (sms-list) of my modem

but i got this error 125002 which means that my token value is not accurate

here is my code


import hashlib
import base64
import binascii
import xml.etree.ElementTree as ET
from datetime import datetime
import requests
from bs4 import BeautifulSoup

BASEURL = 'http://192.168.8.1'


session = requests.Session()
reqresponse = session.get(BASEURL + '/api/webserver/SesTokInfo')
if reqresponse.status_code == 200:
        root = ET.fromstring(reqresponse.text)
        for results in root.iter('SesInfo'):
            sessionid = results.text
            print("the sessionId is", sessionid)
        for results in root.iter('TokInfo'):
            token = results.text
            print("The token is", token)
        sessioncookies = reqresponse.cookies

post_data = '<?xml version = "1.0" encoding = "UTF-8"?>\n'
post_data += '<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount><BoxType>1</BoxType><SortTyp$

headers = {'Content-Type': 'text/xml; charset=UTF-8',
               '__RequestVerificationToken': token,'X-Requested-With: XMLHttpRequest'}

api_url = BASEURL + '/api/sms/sms-list'
logonresponse = session.post( api_url, data=post_data, headers=headers, cookies=sessioncookies)


result = BeautifulSoup(logonresponse.text, 'html.parser')

for r in result:
    print(r)
from this bash script, i m getting all my message list and it is almost the same principle

RESPONSE=`curl -s -X GET http://192.168.8.1/api/webserver/SesTokInfo`
COOKIE=`echo "$RESPONSE"| grep SessionID=| cut -b 10-147`
TOKEN=`echo "$RESPONSE"| grep TokInfo| cut -b 10-41`


DATA="<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount> 
<BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending> 
<UnreadPreferred>1</UnreadPreferred></request>"

curl -b $COOKIE -c $COOKIE -H "X-Requested-With: XMLHttpRequest" --data 
"$DATA" http://192.168.8.1/api/sms/sms-list --header 
"__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml"
what did i missed in python please?