我的目标是能够html/xml data从受密码保护的页面进行解析,然后根据我需要发送xml commands到另一台设备的数据(时间戳)进行解析。我试图访问的页面是由 IP 设备生成的网络服务器。另外,如果用另一种语言更容易完成,请告诉我。我的编程经验很少(一门C编程课)
我曾尝试使用 Requests for Basic 和 Digest Auth。我仍然无法通过身份验证,这使我无法进一步了解。
这是我的尝试:
import requests
from requests.auth import HTTPDigestAuth
url='http://myUsername:myPassword@example.com/cgi/metadata.cgi?template=html'
r = requests.get(url, auth=HTTPDigestAuth('myUsername', 'myPassword'))
r.status_code
print(r.headers)
print(r.status_code)
Run Code Online (Sandbox Code Playgroud)
输出:
401
CaseInsensitiveDict({'Content-Length': '0', 'WWW-Authenticate': 'Digest realm="the realm of device", nonce="23cde09025c589f05f153b81306928c8", qop="auth"', 'Server': 'Device server name'})
Run Code Online (Sandbox Code Playgroud)
我也尝试BasicAuth过请求并获得相同的输出。我已经尝试过包括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: …Run Code Online (Sandbox Code Playgroud)