我不知道如何摆脱这个错误。我确实阅读过有关更改sys.path的内容,但我不明白该怎么做,因为它根本不起作用。有人可以帮我解决这个错误吗?
ImportError at /accounts/register/
No module named 'honeygen'
回溯:
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Adila\Documents\tryFOUR\src\register\views.py" in register
13. user = form.save(commit=False)
File "C:\Users\Adila\Documents\tryFOUR\src\custom_user\forms.py" in save
50. user.set_password(self.cleaned_data["password1"])
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\base_user.py" in set_password
105. self.password = make_password(raw_password)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\hashers.py" in make_password
79. hasher = get_hasher(hasher)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\hashers.py" in get_hasher
124. return get_hashers()[0]
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\hashers.py" in get_hashers
91. hasher_cls = import_string(hasher_path)
File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\utils\module_loading.py" in import_string
20. module = import_module(module_path)
File "C:\Users\Adila\Envs\tryFOUR\lib\importlib\__init__.py" in import_module
126. return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\Adila\Documents\tryFOUR\src\honeywordHasher\hashers.py" in <module>
11. from honeygen import (generate_word, generate_tough_nut, TOUGH_NUT_PROBABILITY,
Exception Type: ImportError at /accounts/register/
Exception Value: No module named 'honeygen'
我无法提交我的注册表格,因为我有这个错误。我不知道该怎么做了。
如何正确导入此honeygen.py文件。
我确实试过这些:
来自honeywordHasher.honeygen导入honeygen 来自honeywordHasher进口honeygen
但最终也会出错。
hashers.py:
from __future__ import unicode_literals
import base64
import binascii
import hashlib
import importlib
import string
from django.conf import settings
from honeywordHasher.honeygen import Honeyword
from honeygen import (generate_word, generate_tough_nut, TOUGH_NUT_PROBABILITY,
RANDOM_WORD_PROBABILITY)
from django.core.signals import setting_changed
from django.contrib.auth.hashers import PBKDF2PasswordHasher
from django.utils.crypto import (get_random_string, pbkdf2)
from django.utils.encoding import force_bytes, force_str, force_text
from django.utils.module_loading import import_string
from honeywordHasher.models import Sweetwords
from django.utils.translation import ugettext_noop as _
有人能帮助我吗?
---- ---- EDITED
它在这里:https://github.com/seanjh/security-hw3-honeywords/blob/master/genword.py。我遵循我的honeygen.py的源代码。我只添加一个类名Honeyword
.
.
.
class Honeyword(object):
def closed_syllable():
return choice(CONSONANTS) + choice(VOWELS) + choice(CONSONANTS)
.
.
.
hashers.py:
def encode(self, password, salt, iterations=None):
sweetwords = ['road,models,table']
honeywordtweak = 3
sweetwords_len = len(sweetwords)
if iterations is None:
iterations = self.iterations
sweetwords.extend(honeygen.gen(password, base64, ["passfiles.txt"]))
for i in range(0, 3):
sweetwords.extend(honeywordtweak.tweak(password[i], 3))
random.shuffle(sweetwords)
hashes = []
for swd in sweetwords:
hashes.append(self.hash(swd, salt, iterations))
self.honeydetector.update_index(salt, sweetwords.index(password))
h = Sweetwords(salt=salt, sweetwords = pickle.dumps(hashes))
h.save()
return "%s$%d$%s$%s" %(self.algorithm, iterations, salt, hashes[0])
项目树:
C:.
├───checkout
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ └───__pycache__
├───contact
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ └───__pycache__
├───custom_user
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───honeydetector
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───honeywordHasher
│ ├───migrations
│ │ └───__pycache__
│ └───__pycache__
├───profiles
│ ├───migrations
│ │ └───__pycache__
│ ├───templates
│ │ └───accounts
│ └───__pycache__
├───register
│ ├───migrations
│ ├───templates
│ │ └───accounts
│ └───__pycache__
├───sqlite
├───tryFOUR
│ └───__pycache__
└───__pycache__