Mirkenan Kazımzade - 17155960
#Imports here
server = 'smtp.gmail.com'
port = 587
username = '[email protected]'
password = 'fake'
sender = username
isGMAIL = True
def sendMsg():
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
msg['From'] = sender
msg['To'] = RECIPIENTS
part = MIMEBase('application', 'octet-stream')
part.set_payload(open_zip_file_to_read)
Encode(part)
part.add_header(headers)
msg.attach(part)
smtp = smtplib.SMTP(server, port)
if isGMAIL:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(username, password)
smtp.sendmail(sender, RECIPIENTS, msg.as_string())
smtp.close()
zip(DIRECTORY_OF_IMAGES, NAME_OF_DESTINATION_ARCHIVE) # defined function
try:
sendMsg()
except Exception:
sys.exit('mail failed; %s' % str(exc))
#imports here
mServer = poplib.POP3('mail.sfcn.org')
#Login to mail server
mServer.user(getpass.getuser())
mServer.pass_(getpass.getpass())
#Get the number of mail messages
numMessages = len(mServer.list()[1])
print("You have %d messages." % (numMessages))
print("Message List:")
#List the subject line of each message
for message_list in range(numMessages) :
for msg in mServer.retr(message_list + 1)[1]:
if msg.startswith('Subject'):
print('\t' + msg)
break
mServer.quit()
from ftplib import FTP
from pathlib import Path
file_path = Path('schema.jpg')
with FTP('ftp.server.com', 'USER', 'PWD') as ftp, open(file_path, 'rb') as file:
ftp.storbinary(f'STOR {file_path.name}', file)
import urllib
urllib.urlretrieve('ftp://server/path/to/file', 'file')
The XML-RPC is a XML based protocol. It is a simple protocol used to exchange information between computer systems over a network. It is a remote procedure call and it uses XML to encode the calls.
XML-RPC server
from xmlrpc.server import SimpleXMLRPCServer
def add(x, y):
return x + y
def sub(x, y):
return x - y
srv = SimpleXMLRPCServer(('localhost', 5080))
srv.register_function(add, 'add')
srv.register_function(sub, 'sub')
srv.serve_forever()
XML-RPC client
import xmlrpc.client
with xmlrpc.client.ServerProxy('http://localhost:5080/') as proxy:
print("sum of 1 and 1 is: %s" % str(proxy.add(1, 1)))
print("subtraction of 2 from 5 is: %s" % str(proxy.sub(5, 2)))
Also link to the code: Gist GitHub
What is SOAP?
SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers. SOAP is an application of the XML specification.
- SOAP is more verbose, but more capable.
- RPC, on the other hand, has more python support than that of SOAP.
- SOAP supports document-level transfer, whereas xml-rpc is more about values transfer, although it can transfer structures such as structs, lists, etc.
- xml-rpc is really about program to program language agnostic transfer. It primarily goes over http/https. SOAP messages can go over email as well.
- xml-rpc is more unixy. It lets you do things simply, and when you know what you're doing, it's very fast to deploy quality web services, even when using terminal text editors. Doing SOAP that way is a zoo; you really need a good IDE to make it feasible.
- Knowing SOAP, though, will look much better on your resume/CV if you're vying for a Fortune 500 IT job.
- xml-rpc has some issues with non-ascii character sets.
- XML-RPC does not support named parameters. They must be in correct order. Not sure about SOAP, but think so.
Google seams to be consistent in implementing their web services to use SOAP, with the exception of Blogger, which uses XML-RPC. You will find SOAP web services in lots of enterprise software as well.
It's not actually messaging protocol but rather architectural approach
- No expensive tools require to interact with the web service
- Smaller learning curve
- Efficient (SOAP uses XML for all messages, REST can use smaller message formats)
- Fast (no extensive processing required)
- Closer to other web technologies in design philosophy
- Language, platform, and transport independent (REST requires use of HTTP)
- Works well in distributed enterprise environments (REST assumes direct point-to-point communication)
- Standardized
- Provides significant pre-build extensibility in the form of the WS* standards
- Built-in error handling
- Automation when used with certain language products