Not able to convert to string










0














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?










share|improve this question




























    0














    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?










    share|improve this question


























      0












      0








      0







      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?










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 9:48









      Black Thunder

      2,2203831




      2,2203831










      asked Nov 9 at 6:55









      Bes

      81




      81






















          3 Answers
          3






          active

          oldest

          votes


















          0














          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'
          >>>





          share|improve this answer






















          • 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


















          1














          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






          share|improve this answer


















          • 1




            Yeah or .format(*bes)
            – Anton vBR
            Nov 9 at 7:23


















          0














          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.





          share|improve this answer






















            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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'
            >>>





            share|improve this answer






















            • 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















            0














            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'
            >>>





            share|improve this answer






















            • 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













            0












            0








            0






            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'
            >>>





            share|improve this answer














            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'
            >>>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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
















            • 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













            1














            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






            share|improve this answer


















            • 1




              Yeah or .format(*bes)
              – Anton vBR
              Nov 9 at 7:23















            1














            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






            share|improve this answer


















            • 1




              Yeah or .format(*bes)
              – Anton vBR
              Nov 9 at 7:23













            1












            1








            1






            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






            share|improve this answer














            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







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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












            • 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











            0














            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.





            share|improve this answer



























              0














              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.





              share|improve this answer

























                0












                0








                0






                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.





                share|improve this answer














                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.






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 11 at 9:51









                Black Thunder

                2,2203831




                2,2203831










                answered Nov 9 at 6:57









                mukesh kudi

                616417




                616417



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo