아래는 최소한의 작업 예제를 얻었다. 나는 이것을 파이썬 3.4, 파이썬 3.6 32 비트, 파이썬 3.6 64 비트로 테스트했다.LXML - 형식 오류 : 쓰기() 예기치 않은 키워드 인수 'default_namespace'
import io
from lxml import etree
test_node = etree.fromstring('''
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
<soap:Body>
<ns1:RequestSecurityToken/>
</soap:Body>
</soap:Envelope>''')
output = io.BytesIO(b'<?xml version="1.0" encoding="UTF-8"?>')
test_node.getroottree().write(output,
encoding="UTF-8",
xml_declaration=None,
default_namespace=None,
method="c14n",
short_empty_elements=False
)
output.seek(0)
print(output.read())
결과 :
Traceback (most recent call last):
File "C:/not_telling/c14n.py", line 16, in <module>
short_empty_elements=False
File "lxml.etree.pyx", line 1869, in lxml.etree._ElementTree.write (src\lxml\lxml.etree.c:57004)
TypeError: write() got an unexpected keyword argument 'short_empty_elements'
난 그냥 4.0.0로 LXML 버전을 업그레이드했다. (하지만 3.7 문제도 마찬가지입니다.)
C14N 방식으로 내보내고 싶지만 (예제에는 포함되어 있지 않지만) 결과 정식 형식으로 표시해야하는 네임 스페이스 목록을 지정해야합니다. . 예 : inclusive_ns_prefixes 매개 변수도 사용해야합니다.
업데이트 : 실제로, 파이썬의 XML 모듈에 내장, LXML하지에 문제가 될 것으로 보인다. 여기
내가 전화 했어하는 방법입니다 :https://github.com/python/cpython/blob/master/Lib/xml/etree/ElementTree.py#L721
그것은 short_empty_elements 매개 변수를 가지고 있지만 그것을 허용하지 않습니다.
short_empty_elements 매개 변수를 제거 하시겠습니까? – AK47
[3.9에서 수정] (https://github.com/seveas/python-hpilo/commit/02dca196a1e2640d4ecc8985285dc15a7ec27ded) – AK47
short_empty_elements 매개 변수를 삭제하고 싶지 않습니다.이를 False로 설정해야하기 때문에! 그리고 그것은 hpilo가 아닌 lxml의 버그 인 것 같습니다. (실수로 두 프로젝트를 혼합했습니다.) – nagylzs