2024-09-30 04:30:09 发布
网友
如果密码包含“@”字符,则从私有pypi安装包失败
所以如果我有 登录名:someLogin 密码:password@
那么我的pip.conf公司看起来像:
[global] extra-index-url = https://someLogin:Password@@nexus.privatepypy.com/repository/pypi/xxx
但这实际上行不通。我必须一直输入密码。在
有什么解决办法吗?在
PS:更改密码不是解决方案:-)
也许你需要百分之百地浏览它,因为它是一个URL。在
>>> from urllib.parse import quote_plus >>> quote_plus('Password@') 'Password%40'
例如,在Mongo中,要进行连接,可以使用:
http://api.mongodb.com/python/current/examples/authentication.html#percent-escaping-username-and-password
-编辑-
我按照pip中的代码:
https://github.com/pypa/pip/blob/1ea3f89ff9f005c78413907b36e55b3e76092612/src/pip/_internal/download.py#L140
并手动运行代码,同时引用和不引用密码:
未引用:
>>> from urllib import parse as urllib_parse >>> url = 'https://someLogin:Password@@nexus.privatepypy.com/repository/pypi/xxx' >>> parsed = urllib_parse.urlparse(url) >>> parsed ParseResult(scheme='https', netloc='someLogin:Password@@nexus.privatepypy.com', path='/repository/pypi/xxx', params='', query='', fragment='') >>> netloc = parsed.netloc.rsplit("@", 1)[-1] >>> netloc 'nexus.privatepypy.com' >>> url = urllib_parse.urlunparse(parsed[:1] + (netloc,) + parsed[2:]) >>> url 'https://nexus.privatepypy.com/repository/pypi/xxx' >>> def parse_credentials(netloc): ... if "@" in netloc: ... userinfo = netloc.rsplit("@", 1)[0] ... if ":" in userinfo: ... user, pwd = userinfo.split(":", 1) ... return (urllib_parse.unquote(user), urllib_parse.unquote(pwd)) ... return urllib_parse.unquote(userinfo), None ... return None, None >>> username, password = parse_credentials(parsed.netloc) >>> username, password ('someLogin', 'Password@')
引用:
>>> url = 'https://{}:{}@nexus.privatepypy.com/repository/pypi/xxx'.format( ... urllib_parse.quote_plus('someLogin'), ... urllib_parse.quote_plus('Password@'), ... ) >>> url 'https://someLogin:Password%40@nexus.privatepypy.com/repository/pypi/xxx' >>> parsed = urllib_parse.urlparse(url) >>> parsed ParseResult(scheme='https', netloc='someLogin:Password%40@nexus.privatepypy.com', path='/repository/pypi/xxx', params='', query='', fragment='') >>> username, password = parse_credentials(parsed.netloc) >>> username, password ('someLogin', 'Password@')
正如你所见,在这两种情况下,它都应该有效。因为我可以确认pip取消了用户名和密码的引用,所以最好引用它们。在
如果它仍然不起作用,我会检查pip版本或归档一个bug。在
也许你需要百分之百地浏览它,因为它是一个URL。在
例如,在Mongo中,要进行连接,可以使用:
http://api.mongodb.com/python/current/examples/authentication.html#percent-escaping-username-and-password
^{pr2}$-编辑-
我按照pip中的代码:
https://github.com/pypa/pip/blob/1ea3f89ff9f005c78413907b36e55b3e76092612/src/pip/_internal/download.py#L140
并手动运行代码,同时引用和不引用密码:
未引用:
引用:
正如你所见,在这两种情况下,它都应该有效。因为我可以确认pip取消了用户名和密码的引用,所以最好引用它们。在
如果它仍然不起作用,我会检查pip版本或归档一个bug。在
相关问题 更多 >
编程相关推荐