Not able to convert to string
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)
#print(bes[0]+"/"+bes[1]+"/"+bes[2])
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?
python python-3.x
add a comment |
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)
#print(bes[0]+"/"+bes[1]+"/"+bes[2])
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?
python python-3.x
add a comment |
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)
#print(bes[0]+"/"+bes[1]+"/"+bes[2])
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?
python 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)
#print(bes[0]+"/"+bes[1]+"/"+bes[2])
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?
python python-3.x
python python-3.x
edited Nov 11 at 9:48
Black Thunder
2,2203831
2,2203831
asked Nov 9 at 6:55
Bes
81
81
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Simply use:
print(time.strftime("%m/%d/%y",dexpires))
See also https://docs.python.org/3/library/time.html
In general python modules usually contain all kinds of reformatting functions you don't have to reinvent them.
Example:
>>> dexpires=time.strptime('20180823131455z','%Y%m%d%H%M%Sz')
>>> dexpires
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=23, tm_hour=13, tm_min=14, tm_sec=55, tm_wday=3, tm_yday=235, tm_isdst=-1)
>>> time.strftime('%m/%d/%y',dexpires)
'08/23/18'
>>>
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
add a comment |
You can use Python's format()
method to handle it (much cleaner also):
print("0/1/2".format(bes[0],bes[1],bes[2]))
...or further simplified (thanks Anton)
print("0/1/2".format(*bes))
↳ Python String Formatting
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
add a comment |
First you have to convert int values to string than only you are able to concave them.
You can use str()
inbuilt method
print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2])) #convert int to str first.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221106%2fnot-able-to-convert-to-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply use:
print(time.strftime("%m/%d/%y",dexpires))
See also https://docs.python.org/3/library/time.html
In general python modules usually contain all kinds of reformatting functions you don't have to reinvent them.
Example:
>>> dexpires=time.strptime('20180823131455z','%Y%m%d%H%M%Sz')
>>> dexpires
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=23, tm_hour=13, tm_min=14, tm_sec=55, tm_wday=3, tm_yday=235, tm_isdst=-1)
>>> time.strftime('%m/%d/%y',dexpires)
'08/23/18'
>>>
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
add a comment |
Simply use:
print(time.strftime("%m/%d/%y",dexpires))
See also https://docs.python.org/3/library/time.html
In general python modules usually contain all kinds of reformatting functions you don't have to reinvent them.
Example:
>>> dexpires=time.strptime('20180823131455z','%Y%m%d%H%M%Sz')
>>> dexpires
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=23, tm_hour=13, tm_min=14, tm_sec=55, tm_wday=3, tm_yday=235, tm_isdst=-1)
>>> time.strftime('%m/%d/%y',dexpires)
'08/23/18'
>>>
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
add a comment |
Simply use:
print(time.strftime("%m/%d/%y",dexpires))
See also https://docs.python.org/3/library/time.html
In general python modules usually contain all kinds of reformatting functions you don't have to reinvent them.
Example:
>>> dexpires=time.strptime('20180823131455z','%Y%m%d%H%M%Sz')
>>> dexpires
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=23, tm_hour=13, tm_min=14, tm_sec=55, tm_wday=3, tm_yday=235, tm_isdst=-1)
>>> time.strftime('%m/%d/%y',dexpires)
'08/23/18'
>>>
Simply use:
print(time.strftime("%m/%d/%y",dexpires))
See also https://docs.python.org/3/library/time.html
In general python modules usually contain all kinds of reformatting functions you don't have to reinvent them.
Example:
>>> dexpires=time.strptime('20180823131455z','%Y%m%d%H%M%Sz')
>>> dexpires
time.struct_time(tm_year=2018, tm_mon=8, tm_mday=23, tm_hour=13, tm_min=14, tm_sec=55, tm_wday=3, tm_yday=235, tm_isdst=-1)
>>> time.strftime('%m/%d/%y',dexpires)
'08/23/18'
>>>
edited Nov 11 at 9:11
answered Nov 9 at 7:26
Gnudiff
3,32111821
3,32111821
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
add a comment |
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
i get this error when i try this solution: AttributeError: 'time.struct_time' object has no attribute 'strftime'
– Bes
Nov 11 at 7:25
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
@Bes Sorry, yes, you had to call module function, not the function of the particular time object. Changed the syntax.
– Gnudiff
Nov 11 at 9:11
add a comment |
You can use Python's format()
method to handle it (much cleaner also):
print("0/1/2".format(bes[0],bes[1],bes[2]))
...or further simplified (thanks Anton)
print("0/1/2".format(*bes))
↳ Python String Formatting
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
add a comment |
You can use Python's format()
method to handle it (much cleaner also):
print("0/1/2".format(bes[0],bes[1],bes[2]))
...or further simplified (thanks Anton)
print("0/1/2".format(*bes))
↳ Python String Formatting
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
add a comment |
You can use Python's format()
method to handle it (much cleaner also):
print("0/1/2".format(bes[0],bes[1],bes[2]))
...or further simplified (thanks Anton)
print("0/1/2".format(*bes))
↳ Python String Formatting
You can use Python's format()
method to handle it (much cleaner also):
print("0/1/2".format(bes[0],bes[1],bes[2]))
...or further simplified (thanks Anton)
print("0/1/2".format(*bes))
↳ Python String Formatting
edited Nov 11 at 9:48
Black Thunder
2,2203831
2,2203831
answered Nov 9 at 7:07
l'L'l
29.6k54891
29.6k54891
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
add a comment |
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
1
1
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
Yeah or .format(*bes)
– Anton vBR
Nov 9 at 7:23
add a comment |
First you have to convert int values to string than only you are able to concave them.
You can use str()
inbuilt method
print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2])) #convert int to str first.
add a comment |
First you have to convert int values to string than only you are able to concave them.
You can use str()
inbuilt method
print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2])) #convert int to str first.
add a comment |
First you have to convert int values to string than only you are able to concave them.
You can use str()
inbuilt method
print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2])) #convert int to str first.
First you have to convert int values to string than only you are able to concave them.
You can use str()
inbuilt method
print(str(bes[0])+"/"+ str(bes[1])+"/"+ str(bes[2])) #convert int to str first.
edited Nov 11 at 9:51
Black Thunder
2,2203831
2,2203831
answered Nov 9 at 6:57
mukesh kudi
616417
616417
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53221106%2fnot-able-to-convert-to-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown