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     = 'user_name@company.com'
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     = 'user_name@company.com'
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
petezurich
  • 9,280
  • 9
  • 43
  • 57
Tad
  • 811
  • 8
  • 16

0 Answers0