ET.fromstring 传进去 unicode 字符串提示 UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 76-99: ordinal not in range(128)。

encode(‘utf-8′) 后传进去提示 ValueError: multi-byte encodings are not supported,不支持多字节编码。

python 的中文支持真是头痛,这个如果用 sys.setdefaultencoding=’utf-8’ 可以解决,但是觉得直接为了这个直接修改了全局编码不太好,最后发现可以用如下代码解决:

Python
1
2
3
4
5
6
7
8
9
:
ET
:
ET
 
 
)
)
)

https://gist.github.com/GameXG/89b92a9a94456ff2da85

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-08-23
  • 2022-01-26
  • 2022-01-12
  • 2021-09-06
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
相关资源
相似解决方案