Reputation: 325
Traceback (most recent call last): File "C:/Users/A6002043/PycharmProjects/IPT-Autobot/mybot.py", line 3, in import slack ModuleNotFoundError: No module named 'slack'
No code changed were made , but i did some mess up with interpreter settings after which i feel i started getting the error
Here is the code
import os
import re
import slack
import logging
import string
from subprocess import check_output
import datetime
@slack.RTMClient.run_on(event='message')
def say_hello(**payload):
try:
##0 get clients and payload
logging.info('msg received')
data = payload['data']
web_client = payload['web_client']
rtm_client = payload['rtm_client']
##0 - 1 Check if it is the first msg, not replied msg by me
#print(data)
if data.get('text') == None:
logging.info('This msg is my replied msg.')
return False
##0-2 Get channel info
channel_id = data['channel']
thread_ts = data['ts']
user = data['user']
##1 get scenario submsg
msg = data['text']
retVal = analysis_msg(msg)
# print(retVal)
if retVal == False:
retMsg = "This message is not for testing. Please check the message format.\nFEATURE_ID:SKU:FULFILLMENT"
send_msg(web_client, channel_id, thread_ts, user, retMsg)
return False
##2 form cmd
retVal = form_cmd(retVal)
print(retVal)
if retVal == False:
return False
##3 execute cmd
#inform the start of test
retMsg = "Testing is going on.... Please wait for the result."
send_msg(web_client, channel_id, thread_ts, user, retMsg)
try:
res1 = check_output(retVal, shell=True).decode()
res = reg_result(res1)
if res == False:
res = "The test scenario has no correct result."
except Exception as ee:
res = "The test scenario has a failure. Please Check the feature file."
## 4 send result to slack
retMsg = "The result is here.\n" + res
create_result_file(user, res)
send_msg(web_client, channel_id, thread_ts, user, retMsg)
print(retVal)
except Exception as e:
print("error")
logging.critical(str(e))
############################ My handlers ##############################
def create_result_file(user, res):
try:
cur_time = datetime.datetime.now()
file_name = user + str(cur_time.year) + str(cur_time.month) + str(cur_time.day) + str(cur_time.hour) + str(cur_time.minute) + str(cur_time.second) + '.txt'
file = open(file_name,'w')
file.write(res)
file.close()
except Exception as e:
print(str(e))
def send_msg(web_client, channel_id, thread_ts, user, mgs):
web_client.chat_postMessage(
channel=channel_id,
text=f"Hi <@{user}>! \n " + mgs,
thread_ts=thread_ts
)
#error code mgmt. ! reserved
def error_code(code):
#reserved
return False
#break donw msg to the test scenario submsgs
def analysis_msg(msg):
submsg = msg.split(":")
if len(submsg) != 3:
logging.warning("This msg not test scenario")
return error_code("NOT_TEST_MSG")
res = {}
res["feature"] = submsg[0]
res["sku"] = submsg[1]
res["fulfillment"] = submsg[2]
return res
#form cmd for test bat files ! reserved
def form_cmd(submsg):
#reserved
cmd = '1.bat'
return cmd
def reg_result(res):
#"COP Order Response"
lines = res.split('\n')
for line in lines:
pattern = "COP Order Response*"
prog = re.compile(pattern)
result = prog.search(line)
if result != None:
print(result.string)
return result.string
return False
slack_token = "xoxb-698180291472-694969165937-zMIG1AfrYCuUgAt44Z46tIgP";#os.environ["SLACK_API_TOKEN"]
rtm_client = slack.RTMClient(token=slack_token)
rtm_client.start()
Error
C:\Users\A6002043\PycharmProjects\IPT-Autobot\venv\Scripts\python.exe C:/Users/A6002043/PycharmProjects/IPT-Autobot/mybot.py
Traceback (most recent call last):
File "C:/Users/A6002043/PycharmProjects/IPT-Autobot/mybot.py", line 3, in <module>
import slack
ModuleNotFoundError: No module named 'slack'
Process finished with exit code 1
Upvotes: 0
Views: 14311
Reputation: 11
looks like you need to install tha package slack for your project: https://www.jetbrains.com/help/pycharm-edu/installing-uninstalling-and-upgrading-packages.html
Upvotes: 1
Reputation: 31
Use pip install to re-install the slack module.
`pip install slack client`
After use :
`from slackclient import SlackClient`
Had the same problem sometime ago, this helped
Upvotes: 1