ironman5366 / W.I.L.L

A python written personal assistant
https://willbeddow.com
MIT License
377 stars 58 forks source link

Answers are displayed correctly in the terminal, but not sent to slack. #21

Closed Rich700000000000 closed 8 years ago

Rich700000000000 commented 8 years ago

So I finally managed to get it working, and it seems to be finding the answers without error. However, whenever I ask it a question in Slack, it gives me 4 InsecurePlatformWarnings and then says the channel is not found:

[11:25:51]: In google search with query: Who is Obama [11:25:52]: wiki_bool is true [11:25:52]: in skwiki [11:25:52]: Barack Obama /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning [11:25:55]: result fetched [11:25:55]: Barack Hussein Obama II (US /brk husen obm/; born August 4, 1961) is an American politician serving as the 44th President of the United States, the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review.

[11:25:55]: Found answer Barack Hussein Obama II (US /brk husen obm/; born August 4, 1961) is an American politician serving as the 44th President of the United States, the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review. , returning it 127.0.0.1 - - [04/Mar/2016 11:25:55] "GET /?context=command&command=Who%20is%20Obama HTTP/1.1" 200 - /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning {"ok":false,"error":"channel_not_found"}

Everything else is working fine, it's getting the queries from slack correctly, it just isn't sending them back. What could be the problem?

ironman5366 commented 8 years ago

From the error it looks like you're using urllib3. I use 2 in all the code, if for some reason it's not finding it and switching to 3 maybe try installing urllib2.

Rich700000000000 commented 8 years ago

Hmm.. I'll try.

Rich700000000000 commented 8 years ago

Ok, so there must be something wrong with my system: I just tried importing urllib, urllib2 and urllib3 in python 2.7 and they all worked fine. I didn't edit any other files besides the JSON. What else do you think could be causing this?

ironman5366 commented 8 years ago

They all worked fine? By that do you mean that the same error kept coming up?

Rich700000000000 commented 8 years ago

I ran: import urllib import urllib2 import urllib3 in python 2.7, and they all ran fine. And yet, I get the same error:

[17:49:54]: Found answer Barack Hussein Obama II (US /brk husen obm/; born August 4, 1961) is an American politician serving as the 44th President of the United States, the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review. , returning it 127.0.0.1 - - [05/Mar/2016 17:49:54] "GET /?context=command&command=Who%20is%20Obama HTTP/1.1" 200 - /usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning {"ok":false,"error":"channel_not_found"}`

ironman5366 commented 8 years ago

Hmmm. I don't know maybe try uninstalling urrlib3?

brenttaylor commented 8 years ago

You can ignore the urllib3 error for now. That's an issue with that library and not this code base. It's also not causing any actual trouble (as far as our application running), it's just a warning.

The real error here is the "channel_not_found" error. Can you post your config.json (with your token and API keys removed)? I'm guessing something in the slack config wasn't filled out quite right.

Rich700000000000 commented 8 years ago

Ok so, I solved part of the problem.

The error message (InsecurePlatformWarning) seemed kind of familiar to me, so I googled it and I was right: I had seen it before, months ago: http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent

Now, It looks like this:

[19:02:55]: in skwiki [19:02:55]: Barack Obama [19:02:59]: result fetched [19:02:59]: Barack Hussein Obama II (US /brk husen obm/; born August 4, 1961) is an American politician serving as the 44th President of the United States, the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review.

[19:02:59]: Found answer Barack Hussein Obama II (US /brk husen obm/; born August 4, 1961) is an American politician serving as the 44th President of the United States, the first African American to hold the office. Born in Honolulu, Hawaii, Obama is a graduate of Columbia University and Harvard Law School, where he served as president of the Harvard Law Review. , returning it 127.0.0.1 - - [05/Mar/2016 19:02:59] "GET /?context=command&command=Who%20is%20Obama HTTP/1.1" 200 - {"ok":false,"error":"channel_not_found"}

As you can see, that's a big improvement: It turns out I was actually getting two different errors at the same time.

Now, why is it saying "Channel Not Found"? Is it still set to your specific channel? Do I have to change that?

brenttaylor commented 8 years ago

You have to set your domain and channel information for slack in your config.json. Mind showing us your config.json file (with your tokens and API keys removed please)?

Rich700000000000 commented 8 years ago

Here:

{ "slack": { "token": "xoxb-24209545930-72CHSWMK413K4IRjfIPNNXth", "domain": "richyearai.slack.com", "username": "willai", "channel": "newexamples" }, "wolfram": { "keys": ["Z6QAAV-8KPEX56RJ9"] }, "autoremote": { "key": "" } }

Don't worry, the key is changed.

brenttaylor commented 8 years ago

There's your problem. Remove ".slack.com" from the domain entry. And again, remove those API keys from your post. You don't want anyone copying them and using them. :)

Rich700000000000 commented 8 years ago

7:36:21 pm EST | Saturday, March 5, 2016 [19:36:21]: Found answer 7:36:21 pm EST | Saturday, March 5, 2016, returning it 127.0.0.1 - - [05/Mar/2016 19:36:21] "GET /?context=command&command=What%20time%20is%20it HTTP/1.1" 200 - {"ok":false,"error":"channel_not_found"}

No, that didn't work.

Rich700000000000 commented 8 years ago

Hey, I have to get back to you tomorrow.

brenttaylor commented 8 years ago

Is "newexamples" one of your slack channels?

brenttaylor commented 8 years ago

Also, channels in slack, much like IRC are prefixed with a pound ("#") symbol. So if "newexamples" is in fact the channel you want will to connect to, change it to "#newexamples".

Rich700000000000 commented 8 years ago

It's working now!

This is what my JSON looks like:

"slack": { "token": "xrxb-24209111430-vgGTSWMK4qtK4IRrRNNXof", "domain": "richyearai.slack.com", "username": "willai", "channel": "#newexamples"

So for future refrence, if you're getting the OkFalseChannelNotFound error, you have to:

  1. Do this: http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent
  2. Make sure that your JSON has the full domain url and a pound (#) sign at the beginning of the channel name.

Thanks for telling me about the pound thing, I would have never figured it out myself.