简体   繁体   English

/accounts/register/ 处的 RuntimeError 线程 'Thread-1' 中没有当前事件循环

[英]RuntimeError at /accounts/register/ There is no current event loop in thread 'Thread-1'

I want to implement an email verification in my django app so, I am using an external module verify_email in that there is a function called verify_email() to check whether an entered email address exists or not. I want to implement an email verification in my django app so, I am using an external module verify_email in that there is a function called verify_email() to check whether an entered email address exists or not. In my view.py file I am checking if the mail is valid then a user is created but, the problem is the function verify_email() takes some time to get the result.在我的 view.py 文件中,我正在检查邮件是否有效,然后创建了一个用户,但是问题是 function verify_email() 需要一些时间才能获得结果。 I think we need to use some kind of await statement to wait for the result but I am getting errors like this when I try to use it normally.我认为我们需要使用某种 await 语句来等待结果,但是当我尝试正常使用它时出现这样的错误。

This is the pypi project link.是 pypi 项目链接。

def register(request):
    if(request.method == 'POST'):
        email = request.POST['email']
        password = request.POST['pass']
        username = request.POST['username']
        check = verify_email(email)
        
        if check:
            user = User.objects.create_user(username,email,password)
            user.save()
            return redirect('/')
        else:
            messages.info(request,'email invalid')
            return redirect('register')

Description of the error:错误描述:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/register/

Django Version: 3.2.3
Python Version: 3.8.5

Traceback (most recent call last):
  File "/home/akshith/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/akshith/.local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/akshith/Desktop/django-app/testing/final (copy)/accounts/views.py", line 55, in register
    check = verify_email(email)
  File "/home/akshith/.local/lib/python3.8/site-packages/verify_email/verify_email.py", line 103, in verify_email
    loop = asyncio.get_event_loop()
  File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

Exception Type: RuntimeError at /accounts/register/
Exception Value: There is no current event loop in thread 'Thread-1'.

Is there a way to use asyncio or any other ways to deal with this kind of error?有没有办法使用 asyncio 或任何其他方式来处理这种错误?

Do you really think that the user should proceed even without email verification?你真的认为即使没有 email 验证用户也应该继续? It usually takes atleast few seconds to verify email on any website, So that should not be a problem.在任何网站上验证 email 通常至少需要几秒钟,所以这应该不是问题。 And for Concurrent requests you don't need to worry because django handles them very efficiently.对于并发请求,您无需担心,因为 django 可以非常有效地处理它们。

And sorry, I didn't had enough reputation to comment:)抱歉,我没有足够的声誉发表评论:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RuntimeError: 线程 'Thread-1' 中没有当前事件循环,多线程和异步错误 - RuntimeError: There is no current event loop in thread 'Thread-1' , multithreading and asyncio error 多线程 python 时的运行时错误“运行时错误:线程 'Thread-1' 中没有当前事件循环。” - RuntimeError when multithreading python "RuntimeError: There is no current event loop in thread 'Thread-1'." 线程 'Thread-1' 中没有当前事件循环 - There is no current event loop in thread 'Thread-1' RuntimeError:线程“ Thread-1”中没有当前事件循环。 -request_html,html.render() - RuntimeError: There is no current event loop in thread 'Thread-1'. - requests_html, html.render() requests-html“RuntimeError:在 flask 端点上使用时,线程‘Thread-1’中没有当前事件循环 - requests-html "RuntimeError: There is no current event loop in thread 'Thread-1' when using it on a flask endpoint python龙卷风websocket错误:RuntimeError:线程'Thread-1'中没有当前事件循环 - python tornado websocket error: RuntimeError: There is no current event loop in thread 'Thread-1' 我不知道如何解决以下错误; RuntimeError:线程“Thread-1”和“Thread-2”中没有当前事件循环 - I don't know how to fix the following error; RuntimeError: There is no current event loop in thread 'Thread-1' and 'Thread-2' 将 Telethon 与 django 一起使用:线程 'Thread-1' 中没有当前事件循环 - Using telethon with django: There is no current event loop in thread 'Thread-1' RuntimeError:线程'Dummy-1'中没有当前事件循环 - RuntimeError: There is no current event loop in thread 'Dummy-1' RuntimeError: There is no current event loop in thread … DiscordPy MultiThreading - RuntimeError: There is no current event loop in thread … DiscordPy MultiThreading
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM