1

启动pypi-server时,我收到一条错误消息,提示“格式错误的 htpasswd 文件”。即使 .htpasswd 文件不存在,我也会收到错误消息。是什么导致了错误?

这是整个 Traceback:

C:\Data>pypi-server -p 8080 -P packages\.htaccess packages
Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pypi-server.exe\__main__.py", line 9, in <module>
  File "c:\python27\lib\site-packages\pypiserver\__main__.py", line 293, in main
    app = pypiserver.app(**vars(c))
  File "c:\python27\lib\site-packages\pypiserver\__init__.py", line 124, in app
    config, packages = core.configure(**kwds)
  File "c:\python27\lib\site-packages\pypiserver\core.py", line 47, in configure
    htPsswdFile = HtpasswdFile(c.password_file)
  File "c:\python27\lib\site-packages\passlib\apache.py", line 583, in __init__
    super(HtpasswdFile, self).__init__(path, **kwds)
  File "c:\python27\lib\site-packages\passlib\apache.py", line 166, in __init__
    self.load()
  File "c:\python27\lib\site-packages\passlib\apache.py", line 236, in load
    self._load_lines(fh)
  File "c:\python27\lib\site-packages\passlib\apache.py", line 261, in _load_lines
    key, value = parse(line, idx+1)
  File "c:\python27\lib\site-packages\passlib\apache.py", line 590, in _parse_record
    % lineno)
ValueError: malformed htpasswd file (error reading line 1)

我有以下文件夹结构:

C:\Data\packages\.htaccess 
C:\Data\packages\.htpasswd

.htaccess 文件的内容是:

AuthName "Under Development"
AuthUserFile C:\Data\packages\.htpasswd
AuthType basic
Require valid-user

.htpasswd 文件的内容是:

user:$apr1$zYBRb3n6$PBrNqfGoyb9ZQC5hGuRJN0
4

1 回答 1

1

pypiserver支持.htaccess文件;这是 Apache 独有的功能。它只是重用了 .htpasswdApache 的文件格式。

另外,htpasswd文件最好不要放在packages文件夹内,以免pypiserver误服,从而泄露其内容。

因此,将 htpasswd 文件例如移动到父文件夹,删除点前缀(无需隐藏/特殊),并更改启动命令:

move packages\.htpasswd .\htpasswd
del packages\.htaccess
pypiserver -p 8080 -P htpasswd packages
于 2016-01-06T17:41:56.607 回答