Python: Why is my Slack-Bot not working in CMD? - python

I'm trying to code a Slack-Bot which is asking for lunch and is taking orders for lunch.
I'm working with this tutorial.
My problem is: I'm trying to run my script in CMD (yes, windows!) but I receive this error:
C:\Users\Dave\PycharmProjects\lunchbot>python lunchbot.py
Traceback (most recent call last):
File "lunchbot.py", line 167, in <module>
if slack_client.rtm_connect(with_team_state=False):
TypeError: rtm_connect() got an unexpected keyword argument 'with_team_state'
This is the part of the code that's not working correctly:
if __name__ == "__main__":
if slack_client.rtm_connect(with_team_state=False):
print("Lunchbot is ready to go!")
starterbot_id = slack_client.api_call("auth.test")["user_id"]
while True:
command, channel = parse_bot_commands(slack_client.rtm_read())
if command:
handle_command(command, channel)
time.sleep(RTM_READ_DELAY)
else:
print("No connection.")
What actually confuses me is every time I'm trying to run this code in my IDE everything is fine. Does anybody have an idea of what could be wrong?

There is a known issue with the websocket-client and Slack. It's buggy and has been a problem for some time now. I wonder if your Pycharm environment is pointing to a different version and hence why it is working.
I would try to force the value of the websocket-client with a known working version.
websocket-client==0.40.0 for example:

Related

"Object has no attribute" bug on one computer, bot not on the other one

I am coding a program which uses a Keras model downloaded from Internet (not my own) to recognize hand movements. It's working very well on my laptop, and I have absolutely 0 issue. However, I tried running the same program on my desktop PC, using the exact same Python version (Python 3.8) and with the same Python modules installed, and it crashed. Here's the error message I get :
Traceback (most recent call last):
File "C:/Users/user/GitHub_Repos/H22-GR10-ReconnaissanceMouvement/Main.py", line 41, in <module>
frame= calculsEtAnalyse(frame, listeMarqueurs)
File "C:/Users/user/GitHub_Repos/H22-GR10-ReconnaissanceMouvement/Main.py", line 32, in calculsEtAnalyse
handProcessor.predictionGeste(listeMarqueurs)
File "C:\Users\user\GitHub_Repos\H22-GR10-ReconnaissanceMouvement\HandTracker.py", line 46, in predictionGeste
prediction = handGestureModel.predict([listeMarqueurs])
AttributeError: '_UserObject' object has no attribute 'predict'
[ WARN:0#16.459] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
It seems to indicate that my handGestureModel object doesn't have the .predict command. Here's the "problematic" code :
handGestureModel = load_model('hand_gesture_dataset')
def predictionGeste(self, listeMarqueurs):
prediction = handGestureModel.predict([listeMarqueurs])
IDGeste = np.argmax(prediction)
nomGeste = handGestureNames[IDGeste]
if(nomGeste != self.pastNomGeste):
print(nomGeste)
self.pastNomGeste = nomGeste
I'm not quite sure what to do because, as I've mentionned, this exact same code works flawlessly on my laptop, with the same Python version and the same modules installed. I even re-cloned my GitHub backup to make sure I hadn't broken something on my desktop.

Syntax for curl commands in Python

I'm developing Python scripts for the automated grading of assignments using CanvasAPI, an API wrapper in Python for the Canvas learning management platform. In studying the documentation, I can successfully issue curl commands in Python for a few parameters. For example, this conversion below is for grading a single submission:
Curl command per the Canvas API docs:
PUT /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:user_id
with
submission[posted_grade]
Turns into this via the CanvasAPI Python wrapper:
edit(submission={'posted_grade': 'grade'})
Where I'm running into difficulties is the more complex parameter for rubrics. Using the same PUT request as above, the syntax in the documentation is as follows:
rubric_assessment[criterion_id][points]
For which I have:
edit(rubric_assessment[{'id': 'criterion_9980'},{'points', '37'}])
However, I get the following error:
Traceback (most recent call last):
File "C:\Users\danie\AppData\Local\Temp\atom_script_tempfiles\2021528-29488-1eagfyw.k8hw", line 39, in <module>
submission = assignment.get_submission(10370)
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\assignment.py", line 203, in get_submission
response = self._requester.request(
File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\site-packages\canvasapi\requester.py", line 255, in request
raise ResourceDoesNotExist("Not Found")
canvasapi.exceptions.ResourceDoesNotExist: Not Found
I suspect I'm fouling up the syntax somewhere along the line. Any suggestions? All help much appreciated.

Webots Attribute Error while getting the robot references

I would like to reproduce the following tutorial, but when I tried to get the robot references theres always this Error:
"AttributeError: 'CartpoleRobot' object has no attribute 'getSelf'"
I rebuild this Tutorial: https://github.com/aidudezzz/deepbots-tutorials/blob/master/robotSupervisorSchemeTutorial/README.md
In other controllers I get similar error messages when I try to get the robot references. I think the error is in the communication between the robot simulation and the controller.
I have tried importing the supervisor and getting the functions via supervisor.get. But here comes another error: "Only one instance of the Robot class should be created"
However, I am new to webots and robotics/informatics in general. Any help would be greatly appreciated!
The whole Error with Traceback:
INFO: robotSupervisorController: Starting controller: python.exe -u robotSupervisorController.py
Traceback (most recent call last):
File "D:\Webots Projekte\controllers\robotSupervisorController\robotSupervisorController.py", line 88, in <module>
env = CartpoleRobot()
File "D:\Webots Projekte\controllers\robotSupervisorController\robotSupervisorController.py", line 16, in __init__
self.robot = self.getSelf() # Grab the robot reference from the supervisor to access various robot methods
AttributeError: 'CartpoleRobot' object has no attribute 'getSelf'
WARNING: 'robotSupervisorController' Controller beendet mit Status: 1
The Code is the same than shown in the Tutorial.
The short section that generates the error:
self.robot = self.getSelf() # Grab the robot reference from the supervisor to access various robot methods
self.positionSensor = self.getDevice("polePosSensor")
self.positionSensor.enable(self.timestep)
If I comment out the first one, the next line returns a similar error
Every answer is highly appreciated! Thanks!
I had the same issue. I use the deepbots-0.1.2 and webotsR2021a.
Try to uninstall the deepbots and then install them using the:
pip install -i https://test.pypi.org/simple/ deepbots

Multiprocessing array .get_lock works on one computer but not another

I am working a somewhat extensive python program that uses multiprocessing. Because I wanted the user to see some progress on the console when running the program, I read about using a shared counter on stackoverflow and after a while of playing around with my code, I got it to work. As I said it's too much code to post here, but the gist is that I instantiate a multiprocessing array after the name==main line,
if __name__ == "__main__":
total_progress_counter = Array('i',[0,0])
and then during the main portion of code I pass this array to a function in other module:
some_name.plot(<other variables>,
total_progress_counter=total_progress_counter)
Then within that other function, I used the .get_lock method that I found described here on stackoverflow:
with total_progress_counter.get_lock():
total_progress_counter[0] += self.total_panels_to_plot
I also update the other component, total_progress_counter[1], in the same function. This works fine for me on my work machine, where I wrote the code, and that machine has a Centos operating system.
But, when I run it on my personal MacBook it gives the following traceback:
Traceback (most recent call last):
File "./program.py", line 775, in <module>
program.run()
File "./program.py", line 177, in run
cases_plotted = pool.map(self.__plot__, all_cases)
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
AttributeError: 'list' object has no attribute 'get_lock'
I have python3 version 3.8.3 on my personal machine and python3 version 3.7.4 on my work machine. Can anyone help me understand why I'm getting different behavior on these two environments? I'd be grateful, as this is meant to be software others might use on different machines.

input syntax in paraview python shell

I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.

Categories