Not able to convert to string

1210 views python-3.x

I might be using wrong python terminology. I have an array of 3 integer elements: month, date and year. However, I am not able to print each individual element when concatenating strings.

import ssl
import OpenSSL
import time
import sys

def get_SSL_Expiry_Date(host, port):
    cert = ssl.get_server_certificate((host, 443))
    x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
    raw_date = x509.get_notAfter()
    decoded_date = raw_date.decode("utf-8")
    dexpires = time.strptime(decoded_date, "%Y%m%d%H%M%Sz")
    bes = dexpires.tm_mon,dexpires.tm_mday,dexpires.tm_year
    print (bes)

domain = sys.argv[1]
port = 443
get_SSL_Expiry_Date(domain, port)

If I uncomment line 14, I get an error: TypeError: unsupported operand type(s) for +: 'int' and 'str'

I am trying to get the date in this format (all strings): Month/Date/Year. What am i doing wrong. Thanks

answered question

1 Answer


First you have to convert int values to string than only you are able to concate them. You can use str() inbuilt method

print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2]))  //convert int to str first.

posted this

Have an answer?


Please login first before posting an answer.