'Huawei hilink (E3372) web api delete-sms returned error 125003
This is my first question, and i'm not a native speaker, please don't be hard on me :)
I'm trying to do sms things with the api read/send is ok, but when it comes to deleting part it always return error 125005, which is i believed related to session and token.
It's very limited information on internets about example on how to used the api.
Here's the scrpt:
#!/bin/bash
MODEM_IP="192.168.9.1"
curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" > ses_tok.xml
COOKIE=`grep "SessionID=""ses_tok.xml | cut -b 10-147`
TOKEN=`grep "TokInfo" ses_tok.xml | cut -b 10-41`
curl -s -X POST "http://$MODEM_IP/api/sms/sms-list" -H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" -d "<request><PageIndex>1</PageIndex><ReadCount>20</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" > modem_status.xml
#cat modem_status.xml
#read index
readarray -t array_index <<< "$(xmlstarlet sel -t -m "//Index" -v . -n modem_status.xml)"
rm -f result_status.xml
touch result_status.xml
for ((i=0; i<${#array_index[@]}; i++ ))
do
index[$i]=$(printf ${array_index[$i]} | tr -d '\n\r ')
#printf "${index[$i]} "
printf "\n${index[$i]}\n" >> result_status.xml
curl -s -X POST "http://$MODEM_IP/api/sms/delete-sms" -H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="UTF-8"?><request><Index>${index[$i]}</Index></request>" >> result_status.xml
done
cat result_status.xml
errors:
<?xml version="1.0" encoding="UTF-8"?>
<error>
<code>125003</code>
<message></message>
</error>
Maybe, i missed something that i didn't notice before.
TIA
Solution 1:[1]
Maybe too late but I had the same issue and maybe this helps also other users looking for it.
In my case the token/cookie already expired right before the delete command. I don't think that it is a time component involved but more like the combination is only valid for one API call.
I get a new token/cookie right before the delete command and now it works for me. Hope this helps.
Cheers Chris
Solution 2:[2]
I faced the same error, in your case you ask for delete sms, I've asked for reboot. Modem should have verified connection based on token, saved in cookies to perform any action.
I've used 3 steps.
1) First is connection to e3372.
<?xml version="1.0" encoding="UTF-8"?><request><dataswitch>1</dataswitch></request>
by /api/dialup/mobile-dataswitch path.
2) Second is getting token by /api/webserver/SesTokInfo path, and save in cookies. python example attached.
def _getTokens(self):
"""Get access tokens"""
try:
xml = self._getXml("/api/webserver/SesTokInfo")
except (URLError, socket.timeout):
return ("", "")
else:
return (xml.findtext("SesInfo", ""), xml.findtext("TokInfo", ""))
def _updateTokens(self):
session, postToken = self._getTokens()
self._opener.addheaders = [("__RequestVerificationToken", postToken),
("Cookie", session)]
3) Reboot modem.
<?xml version="1.0" encoding="UTF-8"?><request><Control>1</Control></request>
by /api/device/control path.
Solution 3:[3]
As this was the top result for Huawei 125003 I'll add my findings when hitting this error.
On the B315s that I have the __RequestVerificationToken can only be used once.
Every POST request should have a response header of __RequestVerificationToken you can just take this value and use it for the next request. Just note that the response to /api/user/login will return a number of tokens that you can use, they are separated by the hash # symbol.
Also keep on top of your cookies, the SesInfo saved from /api/webserver/SesTokInfo will change once you've successfully logged in.
Solution 4:[4]
As of 2020 or so, not sure if python works exactly the same but curl and .net framework need the SessionID presented as a cookie and not a cookie in the header. Like the following, note the -b option in curl:
cmd_output=$(curl -s -X GET "http://192.168.8.1/api/webserver/SesTokInfo")
COOKIE=$(echo $cmd_output | cut -b 58-185)
TOKEN=$(echo $cmd_output | cut -b 205-236)
curl -s -X POST "http://192.168.8.1/api/sms/sms-list" **-b "SessionID=$COOKIE"** -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: text/xml" -d "<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | C. Jani |
| Solution 2 | |
| Solution 3 | Artesea |
| Solution 4 | Tyler2P |
