Forums

Can't get discord-webhook to work

I'm pretty sure I've installed the module correctly onto my virtual environment but it doesn't seem to fine the module when you import it on the python file is there anyone that can provide any help on this?

For the code run it is literally simple on the github page :

from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url='your webhook url', content='Webhook Message') response = webhook.execute()

What is the exact error message that you're getting?

ModuleNotFoundError: No module named 'discord_webhook'

pip install discord-webhook is what I used in the console to install the module in my venv should be there not sure what is wrong.

This is the module: https://pypi.org/project/discord-webhook/

Make sure you're running your code in the same venv that you've installed the module for.

I'm sure I've installed it in the same venv because every other module I have installed is there. I only ever get this problem for discord-webhook.

If you have success setting up a web app with this please let me know the exact instructions you have used to get it to work. I would appreciate it.

Where are you getting the error -- in a website's error log, or in a console? If it's in a console, how are you creating that -- from the "Consoles" page or by running your script from the editor?

From my original post I was getting it in the web app Error log after I pressed the run button. I will get the same error when opening up my python file in pythonanywhere and running it in a console from there.

I guess more specifically I have followed this from you guys step by step and it still doesn't work (running the web app is when I get error) and I will look into error log for web app.

https://help.pythonanywhere.com/pages/RebuildingVirtualenvs

I'm a bit confused -- if you run something using the "run" button, it won't print anything to the website's error log -- those are different parts of the system. Do you mean that it's printing it into the console that appears under the editor when you run the code from there? If so, then you'll need to tell the system which virtualenv to use, because changes that you make to your website on the "Web" page don't affect what happens when you run code in the editor. You can specify the virtualenv to use when running from the editor using the instructions on this help page.

I have specified on my web app which venv to use, the only venv I have set up so it is using that one.

What I mean when running is in the web app where it says "reload user.pythonanywhere.com" is when I am running it and then I can look in the error log which is gives me what I am talking about.

Are you running this in a different account to the one you're using to post here in the forums? I don't see a website associated with your account.

So the problem originally occurred from a problem I had with my app on another account and it is currently using a different module for the webhooks - this works but when I tried to update it on that same account to this new webhook module I couldn't get it to work. Hence I opened a new account and tried getting it to work on this account as a complete fresh start but it didn't work still so I opened up this forum post.

I don't see why this makes a difference though I can't get the module to work on either account.

I'm just trying to see the error that you describe in our logs, but there's no website associated with the account "janeprism", nor are there any logs that I can see. Perhaps you could tell us which account the problem is happening in?

I have created a python file bare bones literally just enough to run the file, installed the module in the console as well you can have a look it still doesn't work. I even tried installing it multiple times in multiple consoles and it still can't find it same error. For this I was running the python file directly not reloading the web app. Web app part ignore couldn't do a quick one

File "/home/janeprism/webhooks/webhook_test.py", line 1, in <module> from discord_webhook import DiscordWebhook ModuleNotFoundError: No module named 'discord_webhook'

So you now switched from web app to just running a python script in the console? If so, how do you run it? How do you activate your venv?

As I have said in my previous post that it doesn't work in either web app or directly running the file through the console. I have just added that example so you can help from there on.

You need to install the module in the same virtualenv/python version that you are using to run your code.

It is there and I still get the same error of not being able to find the module? venv modules

If you guys are able to get it to work on your end can you give me a step by step guide of what you have done?

How was your virtualenv created?