"格式错误的htpasswd文件"启动pypi-server时出现错误消息

时间:2016-01-06 14:13:03

标签: python .htaccess pypi .htpasswd passlib

启动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

1 个答案:

答案 0 :(得分:1)

pypiserver 不支持.htaccess个文件;这是一个仅限Apache的功能。它只是重用了Apache的.htpasswd文件格式。

此外,htpasswd文件最好不要位于packages文件夹内, pypiserver 不能错误地提供它,并显示其内容。

所以移动htpasswd文件,例如到父文件夹,删除点前缀(不需要隐藏/特殊),并更改启动命令:

move packages\.htpasswd .\htpasswd
del packages\.htaccess
pypiserver -p 8080 -P htpasswd packages