python请求:post表单数据,一些字段正在更新,但其他字段没有更新

qgelzfjb  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(212)

我正在尝试将表单数据发布到打印机web界面,我可以成功地发布字段,但有某种类型的表单数据似乎无法工作/更新。
我的代码:

import sys
import requests

IP='xxx.xxx.xxx.xxx'

PrinterSession = requests.session()

csrfdata = PrinterSession .get('http://xxx.xxx.xxx.xxx/properties/authentication/login.php')
csrftoken = str(csrfdata.content)[str(csrfdata.content).index('CSRFToken')+18:str(csrfdata.content).index('CSRFToken')+146]

login_data ={
    'webUsername' : 'admin',
    'webPassword' : 'xxxx',
    'CSRFToken' : csrftoken,
    'NextPage' : '/properties/authentication/luidLogin.php',
    '_fun_function' : 'HTTP_Authenticate_fn',
    'frmaltDomain' : 'default',
}

LoginPrinter = PrinterSession.post("http://xxx.xxx.xxx.xxx/userpost/printer.set", data=login_data )

headersSMTP = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*           /*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-US,en;q=0.9',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'Content-Length': '328',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': 'PageToShow=; statusNumNodes=8; statusSelected=n1; frmCompany=; frmIFax=; frmFaxNumber=; frmProtocol=SMB; frmDocumentPath=; frmLoginName=Xerox; frmServerName=; frmNdsContext=; frmSmbShare=Scans; frmNdsTree=; frmIpv6_Host_1=%3A%3A; frmFirstName=David; frmLastName=Fester; frmFriendlyName=SMB%20Scan; frmEmail=dawie180@gmail.com; frmDisplayName=Fester%2C%20David; frmServerVolume=Scans; frmIpv4_1_1=12; frmIpv4_1_2=12; frmIpv4_1_3=12; frmIpv4_1_4=12; frmXrxAdd_1=Hn; frmHnAdd_1=asdasdsdasda; propNumNodes=117; PHPSESSID=457428a534bf077cc6bb0fff7ee80f7f; propSelected=n49; propHierarchy=001010000010000000000000000; WebTimerPopupID=15',
    'Host': '10.241.24.28',
    'Origin': 'https://10.241.24.28',
    'Referer': 'https://10.241.24.28/protocols/smtp/required.php?from=email_req_smtp',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
    'sec-ch-ua-mobile': '?0',
    'Sec-Fetch-Dest': 'frame',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',

}

cookietolist=headersSMTP['Cookie'].split(";")
cookietolist[27]=' PHPSESSID='+PrinterSession.cookies.get_dict()['PHPSESSID']
StringCookie = ";".join(cookietolist)
headersSMTP['Cookie']=StringCookie

postSMTPform = {
    '_fun_function': 'HTTP_Set_Config_Attrib_fn',
    '_fun_function': 'HTTP_CN_Set_fn',
    '_fun_function': 'HTTP_SNMP_Set_SvcMon_fn',
    'NextPage': '/properties/email/required.php',  
    'CSRFToken': csrftoken,
    'POP3_MAILBOX_ADDRESS': 'smtp.test.com',
    'connectivity.smtp.server': 'xxx.xxx.xxx.xxx:25',

}

PostSMTP = PrinterSession.post('http://'+IP+'/dummypost/printer.set', data=postSMTPform, headers=headersSMTP)

通过chrome检查post请求:

Request Headers:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Content-Length: 364
Content-Type: application/x-www-form-urlencoded
Cookie: PHPSESSID=c960f2c4fb2f99c44333e601d3cc6a79; propSelected=n1; propNumNodes=117; WebTimerPopupID=2
Host: 10.241.24.28
Origin: https://10.241.24.28
Referer: https://10.241.24.28/protocols/smtp/required.php?from=email_cfg_over
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: frame
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36

Form Data:

_fun_function: HTTP_Set_Config_Attrib_fn
_fun_function: HTTP_CN_Set_fn
_fun_function: HTTP_SNMP_Set_SvcMon_fn
NextPage: /config_overview/email.php
connectivity.smtp.server: 10.10.10.10:25
POP3_MAILBOX_ADDRESS: test@home.com
CSRFToken: eb590d22d4b0c75038816bd82a26e188f9a49941029c42765dd790cb8acd07b4966f5a910f493f2d839cb36d5d0a77a7632f614e06fcd67019c0f95f508d7da1

所以“pop3\邮箱\地址:test@home.com工作正常,更新打印机中的smtp发件人地址,所有其他字段使用相同的大写和下划线样式键工作正常,但其他字段“connectivity.smtp.server:10.10.10.10:25”不工作,它不会更新打印机中的设置,而且似乎每个使用这个用句点分隔的小写样式的字段都不起作用。
“pop3\邮箱\地址:test@home.com“即使不使用post请求解析头部,也可以正常工作,我在之后添加了头部,但仍然无法工作。不知道我做错了什么。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题