gpt4 book ai didi

python - 尝试从华为调制解调器读取消息时出现错误 125002

转载 作者:行者123 更新时间:2023-12-02 03:09:02 26 4
gpt4 key购买 nike

所以我想阅读我的华为调制解调器中收到的一些短信。为此,我必须从一个页面中获取一个 token 值,然后在我的调制解调器的另一页(短信列表)中重复使用它

但我得到了这个错误 125002,这意味着我的 token 值不准确

这是我的代码

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><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>\n'

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)

从这个 bash 脚本中,我得到了我所有的消息列表,这几乎是相同的原理

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"

请问我在 python 中错过了什么?

最佳答案

我终于解决了我的问题,显然我没有得到正确的 token 和 session ID 值。

这是我的最终代码

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


BASEURL = 'http://192.168.8.1'


session = requests.Session()
reqresponse = session.get(BASEURL + '/api/webserver/SesTokInfo')
if reqresponse.status_code == 200:
_dict = xmltodict.parse(reqresponse.text).get('response', None) #here is the correct method to get sessionid and token values

post_data = '<?xml version = "1.0" encoding = "UTF-8"?>\n'
post_data += '<request><PageIndex>1</PageIndex><ReadCount>'+nb+'</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>\n'

headers = {'Content-Type': 'text/xml; charset=UTF-8','Cookie': _dict['SesInfo'],
'__RequestVerificationToken': _dict['TokInfo']
} ' in the header i m using the correct values of sessionId and Token
api_url = BASEURL + '/api/sms/sms-list'
logonresponse = session.post( api_url, data=post_data, headers=headers)
result = BeautifulSoup(logonresponse.text, 'html.parser')

for r in result:
print(r)

关于python - 尝试从华为调制解调器读取消息时出现错误 125002,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58195192/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com