kakshay21 / verify_email

verify-email can verify any email address by efficiently checking the domain name and pinging the handler to verify its existence.
https://pypi.org/project/verify-email/
MIT License
133 stars 32 forks source link

module 'asyncio' has no attribute 'run' #32

Closed kelmouloudi closed 4 years ago

kelmouloudi commented 4 years ago

Hi,

I use Python 3.6.7 |Anaconda custom (64-bit)| (default, Dec 10 2018, 20:35:02) [MSC v.1915 64 bit (AMD64)] on win32

and I'm trying to use verify_email like this :

from verify_email import verify_email
import re

# opening my contact list : 
with open('contact_list.txt', 'r', encoding='utf-8') as myfile:
    contact_list = myfile.read()

# extracting all emails into a list : 
contact_list = re.findall(r'[\w\.-]+@[\w\.-]+', contact_list)

# verifying if an email exists and printing it : 
for email in contact_list :
    verification = verify_email(email)
    print(email, verification)

But I get this error instead :

...
  File "C:\ProgramData\Anaconda3\lib\site-packages\verify_email\verify_email.py", line 86, in verify_email
    resp = asyncio.run(_verify_email(email, timeout, verify, debug))

AttributeError: module 'asyncio' has no attribute 'run'
kakshay21 commented 4 years ago

Hey @kelmouloudi thanks for reporting, but it’s not a bug. Actually I explicitly ignored previous versions of python while migrating the code base from python 2.7 to 3.7 Check the compatibility here So in the meanwhile, you can upgrade your python version to 3.7 or greater. Otherwise let me know if this doesn’t solve your problem.

kelmouloudi commented 4 years ago

Thank you very much, sorry I didn't see the compatibility info.

kakshay21 commented 4 years ago

@kelmouloudi no problem!

kelmouloudi commented 4 years ago

Sorry to reopen the issue. Now it gives me (I'm on python 3.7) :

`runfile('C:/Users/User/Documents/Mail Chimp/Communiqué de presse/email-validator.py', wdir='C:/Users/User/Documents/Mail Chimp/Communiqué de presse', post_mortem=True) Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/User/Documents/Mail Chimp/Communiqué de presse/email-validator.py', wdir='C:/Users/User/Documents/Mail Chimp/Communiqué de presse', post_mortem=True)

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)

File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/User/Documents/Mail Chimp/Communiqué de presse/email-validator.py", line 10, in verification = verify_email(email)

File "C:\ProgramData\Anaconda3\lib\site-packages\verify_email\verify_email.py", line 86, in verify_email resp = asyncio.run(_verify_email(email, timeout, verify, debug))

File "C:\ProgramData\Anaconda3\lib\asyncio\runners.py", line 34, in run "asyncio.run() cannot be called from a running event loop")

RuntimeError: asyncio.run() cannot be called from a running event loop`

kakshay21 commented 4 years ago

hey @kelmouloudi, I don't see any problem using python 3.7

verify_email git:(master) ✗ python                 
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from verify_email import verify_email
>>> verify_email('foo@gmail.com')
False

Can you tell me how exactly are you running this? Try running python examples.py from this repo. I noticed you're using anaconda which might be running its own async runner (C:\ProgramData\Anaconda3\lib\asyncio\runners.py) and hence there is already an event loop in your case.

thomaschheang commented 4 years ago

Hello @kakshay21,

I have the same error: RuntimeError: asyncio.run() cannot be called from a running event loop

Does this mean that it's not possible to call verify_email() using Anaconda?

kakshay21 commented 4 years ago

Hey @kelmouloudi , @thomaschheang can you try the fix and see if it works in your local? branch: akshay-fix-event-loop

kakshay21 commented 4 years ago

closing the issues as it should work now. @kelmouloudi @thomaschheang