尝试访问某些子项? php urls / endpoints获取总体的硬件健康状态。这里的问题是我只能从浏览器访问带有长Cookie的那些URL /端点。当我尝试使用python和linux cmd行遇到401错误
url_login_page = https://10.10.10.10/designs/imm/index.php
下面是我想使用python&curl访问的可用php,并且能够从浏览器中毫无问题地查看这些php的内容
{"home.php":"1"},{"event-log.php":"4"},{"event-notification.php":"5"},
{"event-notification.php":"5"},{"service-problems.php":"6"},{"servicesettings.php":"7"},{"download-service-data.php":"8"},{"serverfirmware.php":"9"},{"remote-control.php":"10"},
{"server-properties.php":"11"},{"server-actions.php":"12"},{"fanlist.php":"13"},
{"power-modules.php":"14"},{"disk-list.php":"15"},{"memorylist.php":"16"},
{"cpu-list.php":"17"},{"server-timeouts.php":"18"},{"immproperties.php":"19"},
{"user-list.php":"20"},{"network-properties.php":"21"},{"immsecurity.php":"22"},
{"backup-restore.php":"23"},{"pxe-network-boot.php":"28"},{"osfailurescreen.php":"29"},{"feature-on-demand.php":"80"}]
已更新
现在,我可以获取cookie值和带有请求的标头,
import requests
>>> headers = {
'Sec-Fetch-Mode': 'cors',
'Referer': 'https://10.10.10.10/designs/imm/index.php',
'Origin': 'https://10.10.10.10',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded',
}
>>> data = {
'user': 'user',
'password': 'pass',
'SessionTimeout': '1200'
}
>>> response = requests.post('https://10.10.10.10/data/login', headers=headers, data=data)
>>> response.text
u'{"status":"ok","authResult":"0","TimeWait":"0","iteSrc":"0","forwardUrl":"index-console.php",
"redirection":"home.php","token1_name":"ST17A1FA74B","token1_value":"FF7A4A9934170D1E",
"token2_name":"ST25220A3EA","token2_value":"A547237AA8EB5709",
"token3_name":"ST3FD5CF3C9","token3_value":"C97E95BB2097CA95","errorMsg":""}'
>>> response.headers
{'Content-length': '318', 'X-XSS-Protection': '1; mode=block', 'Content-Security-Policy': "default-src 'self';
connect-src 'self' ws://*:3900/ wss://*:3900/; script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline'; font-src 'self' data:", 'X-Content-Type-Options': 'nosniff',
'Set-Cookie': '_appwebSessionId_=24eb46d3ec26bef7efc9b754f8c79548;
path=/; httponly; secure', 'Strict-Transport-Security': 'max-age=31536000;',
'Keep-Alive': 'timeout=60, max=2000',
'Connection': 'keep-alive', 'Pragma': 'no-cache',
'Cache-control': 'no-cache="set-cookie"',
'X-Frame-Options': 'SAMEORIGIN', 'Content-type': 'text/json'}
response.cookies
<RequestsCookieJar[Cookie(version=0, name='_appwebSessionId_', value='24eb46d3ec26bef7efc9b754f8c79548',
port=None, port_specified=False, domain='10.10.10.10', domain_specified=False,
domain_initial_dot=False, path='/', path_specified=True,
secure=True, expires=None, discard=True,
comment=None, comment_url=None, rest={'httponly': None}, rfc2109=False)]>
问题是我尝试使用令牌值和会话ID访问子URL并出现401错误。
url1 = 'https://10.10.10.10/designs/imm/dataproviders/imm_status_hardware.php'
>>> resp = requests.post(url1, headers=response.headers, cookies=response.cookies, data=data, verify=False)
>>> resp
<Response [401]>
>>>
我确定没有以正确的方式尝试标题和cookie
请帮助我如何访问子网址?
答案 0 :(得分:0)
您是否尝试过sessions with the Request库? 我记得在与您类似的情况下使用它来保留一个会话,在该会话中我发出了多个请求,其中后续请求要求某些cookie出现,否则它们将失败。
答案 1 :(得分:-1)
您已经收到JSON格式的响应。只需使用Python中的json库将其提取即可。
import json
然后通过以下方式提取请求r:
data = json.loads(r.text)
data变量将包含请求提取的所有元组。