2, Python automation Operations--business monitoring detailed

Source: Internet
Author: User
Tags starttls

send e-mail module (smtplib)

approximate idea: instantiation SMTP object, connect to SMTP server and open port, call Starttls () method to establish secure link, login account and authorization code, send mail, and finally exit

Script Example:

#!/usr/bin/python

Import Smtplib

Import string

Host= "Smtp.qq.com"

subject= "Test email from Python"

to= "[Email protected]"

send= "[Email protected]"

text= ' Python rules them all! '

BODY = "\ r \ n". Join ((

"From:%s"% send,

' To:%s '% to,

"Subject:%s"% Subject,

"",

Text

))

Server=smtplib. SMTP ()

Server.connect (Host, "587")

Server.starttls ()

Server.login ("[Email protected]", "Lgjahba")

Server.sendmail (Send,to,body)

Server.quit ()

probing Web Quality of service (Pycurl)

idea: Import pycurl module, instantiate CURL object, set test properties, get test result

#!/usr/bin/python

Import Pycurl

Import time

Import Sys

Import Os,sys

Url=input ("Enter the URL want to query:\n")

C=pycurl. Curl ()

C.setopt (Pycurl. Url,url)

C.setopt (Pycurl. connecttimeout,5) # defines the number of request connections

C.setopt (Pycurl. noprogress,1) # block download progress bar

C.setopt (Pycurl. forbid_reuse,1) # Force Disconnect after complete interaction, no reuse

C.setopt (Pycurl. maxredirs,1) # Specifies the maximum number of HTTP redirects is 1

C.setopt (Pycurl. dns_cache_timeout,30) # set the time to save the DNS information in seconds

Indexfile=open (Os.path.dirname (Os.path.realpath (__file__)) + "/content.txt", "WB")

C.setopt (Pycurl. Writeheader,indexfile)

C.setopt (Pycurl. Writedata,indexfile)

Try

C.perform () # Submit Request

Except Exception as E:

Print ("Connection error:", str (e))

Indexfile.close ()

C.close ()

Sys.exit ()

Dns_time=c.getinfo (c.namelookup_time) # get DNS interest Time

Connect_time=c.getinfo (c.connect_time) # Gets the time to establish the connection

Pretransfer_time=c.getinfo (c.pretransfer_time) # Gets the time from establishing the connection to preparing the transfer

Starttransfer_time=c.getinfo (c.starttransfer_time) # Gets the time from when the connection was established to the start of the transfer

Total_time=c.getinfo (c.total_time) # Gets the total time of the transfer

Http_code=c.getinfo (c.http_code) # get HTTP status Code

Size_downland=c.getinfo (c.size_download) # get download package size

Head_size=c.getinfo (c.header_size) # get http header size

Speed_downland=c.getinfo (c.speed_download) # get average download speed

Print ("HTTP Status code :%s"% (Http_code))

Print ("DNS resolution time :%.2f"% (dns_time))

Print (" Establish connection time :%.2f"% (connect_time))

Print (" ready to transfer time :%.2f:"% (Pretransfer_time))

Print (" Transfer start time :%.2f:"% (Starttransfer_time))

Print (" total transfer end time :%.2f"% (total_time))

Print (" download packet size :%d bytes"% size_downland)

Print ("HTTP header size :%d byte"% head_size)

Print (" average download speed :%d bytes/s"% speed_downland)

Indexfile.close ()

C.close ()


2, Python automation Operations--business monitoring detailed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.