我的目标是能够解析html/xml data
从受密码保护的页面,然后根据我需要发送的数据(时间戳)xml commands
到另一台设备。我尝试访问的页面是由 IP 设备生成的网络服务器。
另外,如果用其他语言更容易完成,请告诉我。
我的编程经验很少(一门 C 编程课)
我尝试过使用基本和摘要身份验证请求。我仍然无法获得身份验证,这阻止了我进一步发展。
这是我的尝试:
import requests
from requests.auth import HTTPDigestAuth
url='http://myUsername:[email protected] /cdn-cgi/l/email-protection/cgi/metadata.cgi?template=html'
r = requests.get(url, auth=HTTPDigestAuth('myUsername', 'myPassword'))
r.status_code
print(r.headers)
print(r.status_code)
Output:
401
CaseInsensitiveDict({'Content-Length': '0', 'WWW-Authenticate': 'Digest realm="the realm of device", nonce="23cde09025c589f05f153b81306928c8", qop="auth"', 'Server': 'Device server name'})
我也尝试过BasicAuth
与 Requests 并获得相同的输出。我都尝试过,包括user:pass@
在 url 内,而不是。尽管当我将该输入放入浏览器时它可以工作。
我认为请求处理了标头数据Digest/BasicAuth
但也许我还需要包含标题?
我使用了 Live HTTP headers(firefox) 并得到了这个:
GET /cgi/metadata.cgi?template=html
HTTP/1.1
Host: [Device IP]
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate DNT: 1 Connection: keep-alive
HTTP/1.1 401 Unauthorized WWW-Authenticate: Digest realm="Device Realm", nonce="a2333eec4cce86f78016343c48382d21",
qop="auth"
Server: Device Server Content-Length: 0