我想隐藏 URL 中的密码以进行记录。我希望通过解析、用虚拟密码替换密码和反解析来使用urlparse,但这给了我:
>>> from urllib.parse import urlparse
>>> parts = urlparse('https://user:pass@66.66.66.66/aaa/bbb')
>>> parts.password = 'xxx'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
所以替代方案似乎是this,这似乎有点矫枉过正。
有没有更简单的方法来替换密码,使用标准库?