Python 代码在 Linux 上解析 XML,但在 Mac 上不解析 XML

python code parses xml on linux but not on mac

提问人:SHIVAM SINGH 提问时间:11/14/2023 更新时间:11/14/2023 访问量:53

问:

我有一个代码,它使用 .lxml

from lxml.etree import fromstring


s = """<Abstract><AbstractText>The genus Cinchona is known for a range of alkaloids, such as quinine, quinidine, cinchonine, and cinchonidine. Cinchona bark has been used as an antimalarial agent for more than 400 years. Quinine was first isolated in 1820 and is still acknowledged in the therapy of chloroquine-resistant falciparum malaria; in lower dosage quinine has been used as treatment for leg cramps since the 1940s. Here we report the effects of the quinoline derivatives quinine, quinidine, and chloroquine on human adult and fetal muscle nicotinic acetylcholine receptors (nAChRs). It could be demonstrated that the compounds blocked acetylcholine (ACh)-evoked responses in Xenopus laevis oocytes expressing the adult nAChR composed of αβ𝜀δ subunits in a concentration-dependent manner, with a ranked potency of quinine (IC50 = 1.70 **M), chloroquine (IC50 = 2.22 **M) and quinidine (IC50 = 3.96 **M). At the fetal nAChR composed of ** subunits, the IC50 for quinine was found to be 2.30 **M. The efficacy of the block by quinine was independent of the ACh concentration. Therefore, quinine is proposed to inhibit ACh-evoked currents in a non-competitive manner. The present results add to the pharmacological characterization of muscle nAChRs and indicate that quinine is effective at the muscular nAChRs close to therapeutic blood concentrations required for the therapy and prophylaxis of nocturnal leg cramps, suggesting that the clinically proven efficacy of quinine could be based on targeting nAChRs.</AbstractText></Abstract>"""

print(fromstring(s))

当我在 mac 上运行时,它给了我错误

    print(fromstring(s))
  File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1916, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1796, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1085, in lxml.etree._BaseParser._parseUnicodeDoc
  File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Char 0x0 out of allowed range, line 1, column 2

但是,如果我在 linux 上运行相同的代码,则代码会成功执行。

无法理解问题所在。我能想到的问题与这款苹果芯片处理器有关。

Python XML macOS LXML

评论

0赞 tripleee 11/14/2023
错误消息表明第 1 行上有一个(可能不可见的)控制字符。你真的得到而不是吗?0x00x00
0赞 tripleee 11/15/2023
有了我,我可以准确地重现该错误消息。s = """<\x00Abstract></Abstract>"""
0赞 SHIVAM SINGH 11/15/2023
是的。我不明白.我可以用正则表达式解决这个问题。但我担心的是为什么这个错误只出现在 mac 上,而不出现在 Linux 上,或者当我在数据流上运行时。显然,在数据流上,它在 Linux 环境中运行。0x00x00
0赞 tripleee 11/15/2023
我在 Mac 上,我无法重现您的示例。我的假设仍然是您传入的字符串以某种方式损坏。它真的来自现实中的文件吗?
0赞 tripleee 11/15/2023
值得一提的是,MacOS 14.1.1 (Sonoma)、Python 3.11.3 来自通过 Homebrew; 版本 4.9.3pyenvlxml

答: 暂无答案