How i could to make SSl Connection server using username, password by python?












-1














Hello I would ask if i could do connection to extract some data from Tool Server.



so i making this code but i need to modify it to open this tool with username and password and extract data from My tool server.



import socket
import ssl

HOST, PORT = '10.74.159.82', 31039

def handle(conn):
conn.write(b'GET / HTTP/1.1n')
print(conn.recv() . decode())

def main():
sock = socket.socket(socket.AF_INET)
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
conn = context.wrap_socket(sock, server_hostname=HOST)
try:
conn.connect((HOST, PORT))
handle(conn)
finally:
conn.close()

if __name__ == '__main__':
main()


RESULT

       !! C:UsersAdmin.PyCharmCE2018.1configvenvScriptspython.exe!! C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py
Traceback (most recent call last):
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 22, in <module>
main()
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 16, in main
conn.connect((HOST, PORT))
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1141, in connect
self._real_connect(addr, False)
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1132, in _real_connect
self.do_handshake()
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
Process finished with exit code 1


I'm Beginner so i need to learn and supporting










share|improve this question
























  • That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
    – declension
    Nov 15 '18 at 15:08
















-1














Hello I would ask if i could do connection to extract some data from Tool Server.



so i making this code but i need to modify it to open this tool with username and password and extract data from My tool server.



import socket
import ssl

HOST, PORT = '10.74.159.82', 31039

def handle(conn):
conn.write(b'GET / HTTP/1.1n')
print(conn.recv() . decode())

def main():
sock = socket.socket(socket.AF_INET)
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
conn = context.wrap_socket(sock, server_hostname=HOST)
try:
conn.connect((HOST, PORT))
handle(conn)
finally:
conn.close()

if __name__ == '__main__':
main()


RESULT

       !! C:UsersAdmin.PyCharmCE2018.1configvenvScriptspython.exe!! C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py
Traceback (most recent call last):
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 22, in <module>
main()
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 16, in main
conn.connect((HOST, PORT))
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1141, in connect
self._real_connect(addr, False)
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1132, in _real_connect
self.do_handshake()
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
Process finished with exit code 1


I'm Beginner so i need to learn and supporting










share|improve this question
























  • That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
    – declension
    Nov 15 '18 at 15:08














-1












-1








-1







Hello I would ask if i could do connection to extract some data from Tool Server.



so i making this code but i need to modify it to open this tool with username and password and extract data from My tool server.



import socket
import ssl

HOST, PORT = '10.74.159.82', 31039

def handle(conn):
conn.write(b'GET / HTTP/1.1n')
print(conn.recv() . decode())

def main():
sock = socket.socket(socket.AF_INET)
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
conn = context.wrap_socket(sock, server_hostname=HOST)
try:
conn.connect((HOST, PORT))
handle(conn)
finally:
conn.close()

if __name__ == '__main__':
main()


RESULT

       !! C:UsersAdmin.PyCharmCE2018.1configvenvScriptspython.exe!! C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py
Traceback (most recent call last):
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 22, in <module>
main()
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 16, in main
conn.connect((HOST, PORT))
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1141, in connect
self._real_connect(addr, False)
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1132, in _real_connect
self.do_handshake()
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
Process finished with exit code 1


I'm Beginner so i need to learn and supporting










share|improve this question















Hello I would ask if i could do connection to extract some data from Tool Server.



so i making this code but i need to modify it to open this tool with username and password and extract data from My tool server.



import socket
import ssl

HOST, PORT = '10.74.159.82', 31039

def handle(conn):
conn.write(b'GET / HTTP/1.1n')
print(conn.recv() . decode())

def main():
sock = socket.socket(socket.AF_INET)
context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
conn = context.wrap_socket(sock, server_hostname=HOST)
try:
conn.connect((HOST, PORT))
handle(conn)
finally:
conn.close()

if __name__ == '__main__':
main()


RESULT

       !! C:UsersAdmin.PyCharmCE2018.1configvenvScriptspython.exe!! C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py
Traceback (most recent call last):
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 22, in <module>
main()
File "C:/Users/Admin/.PyCharmCE2018.1/config/codestyles/Under_Building.py", line 16, in main
conn.connect((HOST, PORT))
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1141, in connect
self._real_connect(addr, False)
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1132, in _real_connect
self.do_handshake()
File "C:UsersAdminAppDataLocalProgramsPythonPython37-32libssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1045)
Process finished with exit code 1


I'm Beginner so i need to learn and supporting







python ssl server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:19









declension

3,0411320




3,0411320










asked Nov 15 '18 at 13:23









SamSam

13




13












  • That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
    – declension
    Nov 15 '18 at 15:08


















  • That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
    – declension
    Nov 15 '18 at 15:08
















That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
– declension
Nov 15 '18 at 15:08




That code isn't valid Python. I suggest you fix it / clean up the formatting to help people read and understand your question
– declension
Nov 15 '18 at 15:08












1 Answer
1






active

oldest

votes


















0














It's hard to see exactly, but it seems the server you're connecting to (on https://10.74.159.82:31039) is using a self-signed certificate (or its CA is, perhaps).



It's perhaps better to create or buy a proper (non-self-signed) certificate, but assuming this is a test server this is fine.



So with what you have, your best bet is to allow self-signed certs in your SSL Context (and also, not to check the hostname - that will probably fail too as you're using an IP address):



context = ssl.create_default_context()
context.check_hostname=False
context.verify_mode=ssl.CERT_NONE
# etc...





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%2f53320466%2fhow-i-could-to-make-ssl-connection-server-using-username-password-by-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It's hard to see exactly, but it seems the server you're connecting to (on https://10.74.159.82:31039) is using a self-signed certificate (or its CA is, perhaps).



    It's perhaps better to create or buy a proper (non-self-signed) certificate, but assuming this is a test server this is fine.



    So with what you have, your best bet is to allow self-signed certs in your SSL Context (and also, not to check the hostname - that will probably fail too as you're using an IP address):



    context = ssl.create_default_context()
    context.check_hostname=False
    context.verify_mode=ssl.CERT_NONE
    # etc...





    share|improve this answer


























      0














      It's hard to see exactly, but it seems the server you're connecting to (on https://10.74.159.82:31039) is using a self-signed certificate (or its CA is, perhaps).



      It's perhaps better to create or buy a proper (non-self-signed) certificate, but assuming this is a test server this is fine.



      So with what you have, your best bet is to allow self-signed certs in your SSL Context (and also, not to check the hostname - that will probably fail too as you're using an IP address):



      context = ssl.create_default_context()
      context.check_hostname=False
      context.verify_mode=ssl.CERT_NONE
      # etc...





      share|improve this answer
























        0












        0








        0






        It's hard to see exactly, but it seems the server you're connecting to (on https://10.74.159.82:31039) is using a self-signed certificate (or its CA is, perhaps).



        It's perhaps better to create or buy a proper (non-self-signed) certificate, but assuming this is a test server this is fine.



        So with what you have, your best bet is to allow self-signed certs in your SSL Context (and also, not to check the hostname - that will probably fail too as you're using an IP address):



        context = ssl.create_default_context()
        context.check_hostname=False
        context.verify_mode=ssl.CERT_NONE
        # etc...





        share|improve this answer












        It's hard to see exactly, but it seems the server you're connecting to (on https://10.74.159.82:31039) is using a self-signed certificate (or its CA is, perhaps).



        It's perhaps better to create or buy a proper (non-self-signed) certificate, but assuming this is a test server this is fine.



        So with what you have, your best bet is to allow self-signed certs in your SSL Context (and also, not to check the hostname - that will probably fail too as you're using an IP address):



        context = ssl.create_default_context()
        context.check_hostname=False
        context.verify_mode=ssl.CERT_NONE
        # etc...






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 15:20









        declensiondeclension

        3,0411320




        3,0411320






























            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%2f53320466%2fhow-i-could-to-make-ssl-connection-server-using-username-password-by-python%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

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)