Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求:发布表单数据,一些字段正在更新,但其他字段没有更新_Python_Python Requests - Fatal编程技术网

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

Python请求:发布表单数据,一些字段正在更新,但其他字段没有更新,python,python-requests,Python,Python Requests,我正在尝试将表单数据发布到打印机的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') csrftoke

我正在尝试将表单数据发布到打印机的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检查后请求:

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请求解析标题也可以正常工作,我在之后添加了标题,但仍然不起作用。不知道我做错了什么。

不要手动设置“内容长度”:“328”-您可以发送多于或少于328字节的数据。请求应自动将此标头设置为正确的值。谢谢,我会尝试一下,这似乎是表单字符串的长度,而不是字节,我确实仔细查看了一下,但认为它可能无关紧要。