Skip to content

SSL Certification error #334

Closed
Closed

Description

@sophiefitzpatrick

Description

I've built a bot in python 3.7 using a virtual engine, when I come to run the code I get this error:

/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
Traceback (most recent call last):
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/slackclient/server.py", line 179, in connect_slack_websocket
    http_proxy_auth=proxy_auth)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/websocket/_core.py", line 494, in create_connection
    websock.connect(url, **options)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/websocket/_core.py", line 217, in connect
    options.pop('socket', None))
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/websocket/_http.py", line 126, in connect
    sock = _ssl_socket(sock, options.sslopt, hostname)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/websocket/_http.py", line 253, in _ssl_socket
    sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/websocket/_http.py", line 232, in _wrap_sni_socket
    server_hostname=hostname,
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 850, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/slackclient/client.py", line 52, in rtm_connect
    self.server.rtm_connect(use_rtm_start=with_team_state, **kwargs)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/slackclient/server.py", line 147, in rtm_connect
    self.connect_slack_websocket(self.ws_url)
  File "/Users/sophie/Dropbox/Programming/gallagherbot/lib/python3.7/site-packages/slackclient/server.py", line 186, in connect_slack_websocket
    raise SlackConnectionError(message=str(e))
slackclient.server.SlackConnectionError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)

Connection failed. Exception traceback printed above.

This seems similar to this: #325 but I tried the User's suggestion and it hasn't changed anything.

I have the bot's 'Bot User OAuth Access Token' stored as a variable which I refer to in the code

Any suggestions?

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

  • [x ] bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • [x ] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x ] I've read and agree to the Code of Conduct.
  • [x ] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version:

python version: 3.7

OS version(s):

Steps to reproduce:

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

Activity

  1. KoalaTea commented on Jul 12, 2018

    @KoalaTea

    I have run into the same exact problem today. I fixed it by downgrading the websocket-client library to 0.47.0

  2. aoberoi commented on Jul 13, 2018

    @aoberoi
    Contributor

    Are you both using a proxy configuration? If so, it may be that your proxy has a certificate which doesn't have a root in the CA bundle shipping with this package.

    If that's the case, I see two options:

    1. we allow turning verification of the proxy server off (this would mean sacrificing an important security feature).
    2. we allow you to supply your own CA bundle, but this will require more work on your part to configure correctly.
  3. KoalaTea commented on Jul 13, 2018

    @KoalaTea

    0.48.0 of websocket-client appears to have removed the CA bundle actually which I think the problem is. I am on a Mac, I have not had the chance to test this on another OS to see if the load_default_certs for Mac is the problem.

  4. aoberoi commented on Jul 13, 2018

    @aoberoi
    Contributor

    @KoalaTea wow, you're right, and also that's no great.

    it looks like websocket-client/websocket-client#413 is the issue where this decision was made. i hope the maintainers of that package will consider reversing this decision. for example, the requests package depends on certifi to provide a CA bundle, which seems like a favorable approach to solve the staleness problem. the current approach is untested for py2 and depends on some very specific system configuration to be done correctly (which seems to be misconfigured at least often enough for a couple users of this package).

  5. aoberoi commented on Jul 13, 2018

    @aoberoi
    Contributor

    i made an issue for my suggestion: websocket-client/websocket-client#451. if the maintainers indicate that they'd merge that change in, we can contribute the code.

  6. sophiefitzpatrick commented on Jul 15, 2018

    @sophiefitzpatrick
    Author

    Thanks @KoalaTea and @aoberoi for figuring this out, I'm new to programming - so this is awesome!

  7. dickson-conde commented on Jul 17, 2018

    @dickson-conde

    Also ran into this issue, not sure if work is being done to resolve this or should I just implement a hotfix to my own proj by downgrading the websocket version.

  8. aoberoi commented on Jul 17, 2018

    @aoberoi
    Contributor

    For those of you affected, I think it would be helpful for you to express support of websocket-client/websocket-client#451.

    The easiest way would be click through and put a thumbsup reaction on the top comment.

  9. kamolsj commented on Aug 28, 2018

    @kamolsj

    so I am still running into the same issue here, I am new to python and have tried to downgrade the websocket-client library to 0.47.0, but it still returns the same error!
    any tips on how to get around this?

  10. minus7 commented on Sep 2, 2018

    @minus7

    I named possible solutions in websocket-client/websocket-client#451 (comment) if you care to try.

  11. KoalaTea commented on Sep 13, 2018

    @KoalaTea

    Hey,
    I just ran into a similiar problem in another project and googling has this as the top result bringing me back.
    Doing as you linked fixed the issue.
    "./Applications/Python\ x.x/Install\ Certificates.command" caused it to work. on versions above 0.47.0

  12. added this to the 1.x milestone on Oct 5, 2018
  13. cmaliwal commented on Oct 26, 2018

    @cmaliwal

    There are a couple of things that can be done: 1. Downgrading the websocket-client library to 0.47.0 2. Or, download the certificate (wget https://www.tbs-certificats.com/issuerdata/DigiCertGlobalRootCA.crt), then set the environment variable export WEBSOCKET_CLIENT_CA_BUNDLE=DigiCertGlobalRootCA.crt

  14. rpujakesuma commented on Oct 26, 2018

    @rpujakesuma

    This is sloved my problem..

    cd /Applications/Python\ 3.7/
    ./Install\ Certificates.command
    
  15. 7 remaining items

  16. AlmogCohen commented on May 8, 2019

    @AlmogCohen

    Build is still broken here with the same error...took me some time to realize it is slack related issue and not a general OS issue...

  17. RodneyU215 commented on May 8, 2019

    @RodneyU215
    Contributor

    @AlmogCohen can you provide any more details to your conclusion? I've not been able to discover any issues where the root cause is related to Slack.

  18. AlmogCohen commented on May 8, 2019

    @AlmogCohen

    Since this package was the official one supported by slack for a long time I do have some expectations for it to work including some accountability to the dependencies it is shipped with. Maybe it is too much to expect that. If it says any websocket-client version is OK, but the client is breaking... It is odd to me.

    Also, I did see the v2 SDK and it looks amazing...BUT it is not trivial to shift existing code bases to use it as if it is a drop-in replacement to issues with the v1 SDK. v2 is awesome, but quite different (for good, yet different)

  19. RodneyU215 commented on May 8, 2019

    @RodneyU215
    Contributor

    @AlmogCohen I understand now. Thank you for the feedback. I apologize for the frustration that was caused. I've recently taken on this project and will be leading the development efforts moving forward.

    Next week I'll be switching part of my focus on bug fixing v1 where it makes sense. Around this same time I'll consider locking down the websocket-client version to the previous 0.47.0 version.

    If you can work with Python 3.6+ and would like to use the new v2 SDK. Please open a new issue to let me know if there's anything I can do to ease the migration efforts.

  20. Ogek commented on Jun 27, 2019

    @Ogek

    This is sloved my problem..

    cd /Applications/Python\ 3.7/
    ./Install\ Certificates.command
    

    Worked for me too

    works

  21. VFagundes commented on Aug 11, 2019

    @VFagundes

    that works for me, i've seen it, the aiohttp expects a ssl_context, buuut..
    the web_client really needs to avoid this kind of exception, because the ssl parameter is optional in constructor.

    import ssl
    import slack
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    client = slack.WebClient(token='yourtoken',
                             ssl=ssl_context)
    
    response = client.chat_postMessage(
        channel='#yourchannel',
        text="message, etc..")
    
  22. Omer-Khabeer commented on Aug 24, 2019

    @Omer-Khabeer

    How to downgrade to websocket_client 0.47.0 ? i mean what should I write in Mac terminal to get this done ?

  23. AlmogCohen commented on Aug 24, 2019

    @AlmogCohen
  24. Omer-Khabeer commented on Aug 26, 2019

    @Omer-Khabeer

    it is pip

  25. jayczech23 commented on Jan 7, 2020

    @jayczech23

    that works for me, i've seen it, the aiohttp expects a ssl_context, buuut..
    the web_client really needs to avoid this kind of exception, because the ssl parameter is optional in constructor.

    import ssl
    import slack
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    client = slack.WebClient(token='yourtoken',
                             ssl=ssl_context)
    
    response = client.chat_postMessage(
        channel='#yourchannel',
        text="message, etc..")
    

    This is what fixed it for me.

  26. hackingbutlegal commented on Mar 16, 2020

    @hackingbutlegal

    How to downgrade to websocket_client 0.47.0 ? i mean what should I write in Mac terminal to get this done ?

    pip3 install websocket-client==0.47.0

  27. limoneren commented on Mar 30, 2020

    @limoneren

    that works for me, i've seen it, the aiohttp expects a ssl_context, buuut..
    the web_client really needs to avoid this kind of exception, because the ssl parameter is optional in constructor.

    import ssl
    import slack
    ssl_context = ssl.create_default_context()
    ssl_context.check_hostname = False
    ssl_context.verify_mode = ssl.CERT_NONE
    client = slack.WebClient(token='yourtoken',
                             ssl=ssl_context)
    
    response = client.chat_postMessage(
        channel='#yourchannel',
        text="message, etc..")
    

    This worked for me unlike the other proposed solutions here.

  28. mochoaim commented on Feb 13, 2023

    @mochoaim

    I've also had success setting the ssl context:

    import urllib.request
    import ssl
    
    ssl._create_default_https_context = ssl._create_unverified_context
    r = urllib.request.urlopen('https://google.com')
    print(r.status)
    print(r)
  29. jg75 commented on Nov 14, 2023

    @jg75

    None of these worked for me. I'm on a mac with python 3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions