您好我能夠解析一個正常的xml,如xml = lxml.etree.parse(''http://abc.com/A.xml') 但現在我有這個路徑進行身份驗證用戶名和密碼可以輸入用戶名和密碼並解析url,就像連接數據庫一樣,您可以在連接字符串中輸入用戶名密碼在python中的安全xml解析
1
A
回答
3
夥計們,我發現了一種解析密碼保護XML的方法,這就是我所做的。
import urllib2
import base64
theurl = 'http://abc.com/A.xml'
username='AAA'
password='BBB'
req = urllib2.Request(theurl)
base64string = base64.encodestring(
'%s:%s' % (username, password))[:-1]
authheader = "Basic %s" % base64string
req.add_header("Authorization", authheader)
try:
handle = urllib2.urlopen(req)
except IOError, e:
print "It looks like the username or password is wrong."
xml = handle.read()
inputXml = etree.fromstring(xml)
3
是的,這是可能的。在使用lxml
解析XML文檔之前,您需要通過正確處理HTTP基本/摘要式身份驗證的HTTP請求來獲取它。例如,與urllib2.HTTPBasicAuthHandler
像這樣的解決方案:Python urllib2 HTTPBasicAuthHandler
相關問題
- 1. 安全XML解析器
- 2. 在解析安全
- 3. 在Python中解析XML
- 4. 在GWT中安全的JSON解析?
- 5. 解析XML信封在Python
- 6. Python ElementTree XML解析
- 7. Python BeautifulSoup XML解析
- 8. 用Python解析XML
- 9. 使用XML解析Python XML
- 10. Python的XML解析問題
- 11. Python的XML解析混淆
- 12. Python的體育XML解析
- 13. 的Python解析XML文件
- 14. Python的XML解析問題
- 15. 用python解析URL的XML
- 16. Wolfram Api的Python Xml解析
- 17. Python解析奇怪的XML?
- 18. 在python中使用expat xml解析器
- 19. 使用minidom在python中解析XML
- 20. 在python中使用cElementTree解析XML
- 21. 在Python中使用XMLPullParser解析XML流
- 22. Python ElementTree多解析XML解析
- 23. 從Java中的安全URL解編XML
- 24. 如何在python中使用minidom解析器解析xml文件
- 25. 安卓:XML解析問題
- 26. 解析XML XmlPullParser安卓
- 27. 安卓:SAX解析XML
- 28. Python的XML解析XML屬性
- 29. xml解析python中的大數據
- 30. 如何解析python中的xml文件?
-1。你拒絕接受答案,並且在被告知這樣做時你忽略了這個事實。學會回報。 – user225312 2011-01-11 16:41:17