Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将github数据库添加到Django项目_Python_Django_Database_Github_Web - Fatal编程技术网

Python 将github数据库添加到Django项目

Python 将github数据库添加到Django项目,python,django,database,github,web,Python,Django,Database,Github,Web,我试图在django项目中从github访问这个“常用密码列表”。python函数在terminal中运行良好,但当我在Django项目的views.py文件中使用它并尝试在web文件中执行它时,它给出了“发生服务器错误”。请与管理员联系。'错误。我是Django的新手,我不知道出了什么问题。代码中的第一个问题是您已经编写了这一行quit(),这基本上意味着关闭正在运行的python进程!要从循环中中断,通常使用break语句。接下来,如果密码不匹配,可能会打印出10000!打印到控制台确实需要

我试图在django项目中从github访问这个“常用密码列表”。python函数在terminal中运行良好,但当我在Django项目的views.py文件中使用它并尝试在web文件中执行它时,它给出了“发生服务器错误”。请与管理员联系。'错误。我是Django的新手,我不知道出了什么问题。

代码中的第一个问题是您已经编写了这一行
quit()
,这基本上意味着关闭正在运行的python进程!要从循环中中断,通常使用
break
语句。接下来,如果密码不匹配,可能会打印出10000!打印到控制台确实需要一些时间,打印10000次会使您的请求在服务器向客户端发送响应之前超时。如果没有匹配项,请不要打印,请继续。此外,
ans
val
可能永远不会被定义,这也会导致错误,请在开始时用一些值定义它:

def HashBrut(request):
    
    sha1hash = request.POST.get('decoder','default')
    time.sleep(4)

    LIST_OF_COMMON_PASSWORDS = str(urlopen('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt').read(), 'utf-8')

    for guess in LIST_OF_COMMON_PASSWORDS.split('\n'):

        hashedGuess = hashlib.sha1(bytes(guess, 'utf-8')).hexdigest()
        if hashedGuess == sha1hash:
            val=hashedGuess
            print("The password is ", str(guess))
            ans=str(guess)
            quit()
      
        elif hashedGuess != sha1hash:
            print("Password guess ",str(guess)," does not match, trying next...")

    print("Password not in database, we'll get them next time.")
    params={'text':val,'text1':ans}
    return render(request,'Hashed.html',params)

视图应该返回一个响应。。。您的视图
HashBrut
不会返回任何内容,更不用说响应了。@AbdulAzizBarkat实际上我只上传了一段我认为会产生问题的代码。我现在已经更新并上传了我完整的python函数。谢谢你,它确实对我有用。正如您提到的,服务器占用的时间太长,这导致了错误。再次感谢你的帮助@阿卜杜勒·阿齐兹巴卡特
def HashBrut(request):
    ans, val = None, None
    sha1hash = request.POST.get('decoder','default')
    time.sleep(4)

    LIST_OF_COMMON_PASSWORDS = str(urlopen('https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-10000.txt').read(), 'utf-8')

    for guess in LIST_OF_COMMON_PASSWORDS.split('\n'):

        hashedGuess = hashlib.sha1(bytes(guess, 'utf-8')).hexdigest()
        if hashedGuess == sha1hash:
            val=hashedGuess
            print("The password is ", str(guess))
            ans=str(guess)
            # No `quit()` here! use `break`
            break
        # No print here, takes too much time
    print("Password not in database, we'll get them next time.")
    params={'text':val,'text1':ans}
    return render(request,'Hashed.html',params)