我在SO上看到了一些关于将XML转换为JSON的方法的问题,但我有兴趣转向其他方式.是否有用于将JSON转换为XML的python库?
编辑:没有什么东西马上回来,所以我继续编写了一个解决这个问题的脚本.
Python已经允许您将JSON转换为本机dict(使用json或者在版本<2.6中simplejson),因此我编写了一个将本机dicts转换为XML字符串的库.
https://github.com/quandyfactory/dict2xml
它支持int,float,boolean,string(和unicode),array和dict数据类型以及任意嵌套(yay recursion).
一旦8小时过去,我会将此作为答案发布.
我正在尝试使用urllib2和python-ntlm连接到NT身份验证的服务器,但我收到一个错误.这是我正在使用的代码,来自python-ntlm站点:
user = 'DOMAIN\user.name'
password = 'Password123'
url = 'http://corporate.domain.com/page.aspx?id=foobar'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
# create and install the opener
opener = urllib2.build_opener(auth_NTLM)
urllib2.install_opener(opener)
# retrieve the result
response = urllib2.urlopen(url)
return response.read()
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Traceback (most recent call last):
File "C:\Python27\test.py", line 112, in get_ntlm_data
response = urllib2.urlopen(url)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 398, …Run Code Online (Sandbox Code Playgroud)