2

While I'm trying to logon my outlook e-mail account using python inside a VDI , I'm getting the SOCKET error

CODE:

import imaplib, email, os
user     = '[email protected]'
password = 'my_password'
imap_url = 'outlook.office365.com'

def auth(user,password,imap_url):
    con = imaplib.IMAP4_SSL(imap_url)
    con.login(user,password)
    return con

con = auth(user,password,imap_url)

I'm getting the below error

ERROR:

File "C:\Program Files\Python36\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11003] getaddrinfo failed

I assume that the above error is due to the firewall . Hence I added the below code to bypass the firewall using proxy

import imaplib, email, os

proxy = 'http://<username>:<password>@proxy.company.com:8080'
os.environ['http_proxy'] = proxy 
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy

user     = '[email protected]'
password = 'my_password'
imap_url = 'outlook.office365.com'

def auth(user,password,imap_url):
    con = imaplib.IMAP4_SSL(imap_url)
    con.login(user,password)
    return con

con = auth(user,password,imap_url)

Now, I'm getting the below error . Can someone help me to fix this please?

ERROR:

  File "C:\Program Files\Python36\lib\socket.py", line 724, in create_connection
    raise err
  File "C:\Program Files\Python36\lib\socket.py", line 713, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.