Python + Flask Application - ConnectionRefusedError: [Errno 111]

Hey there. Apologies if this has been answered - Tried to search but no luck.

I’ve deployed a Flask Application on cpanel, and when running my chat bot, I am receiving this error:

Traceback (most recent call last):
File “/opt/alt/python39/lib64/python3.9/”, line 973, in _bootstrap_inner
File “/home/[redacted server name]/virtualenv/I_suck_at_code/3.9/lib/python3.9/site-packages/twitch/chat/”, line 24, in run
File “/home/[redacted server name]/virtualenv/I_suck_at_code/3.9/lib/python3.9/site-packages/twitch/chat/”, line 54, in connect
self.socket.connect((self.address, self.port))
ConnectionRefusedError: [Errno 111] Connection refused

This application works wonderfully on localhost - but when I try to deploy it to the internet, I come across this issue. I’ve ensured the app’s URL is under the Manage Application section in dev.twitch. I’ve ensured the webpage and all subpages / subdomains / everything has SSL attached to it. At this point I’m at a loss. I’ve throw at least 15+ hours at attempting to find a solution but this is the only stopping point.

Part of me thinks its the python-twitch library that I’m using, and I should rewrite everything using socket. :frowning:

Any guidance would be incredible.

So your chat bot is failing to reach Twitch chat when on your production server?

This may indicate your hosting provider disallows running any kind of IRC services on their network.

1 Like

You got it! Okay. I was thinking twitch was refusing the connection on their side as the requests were coming from a server instead of my own pc. That does seem to make sense. Let me reach out to their customer service and see if this is blocked / if there is a way to unblock it.

Is there any specific port I should or shouldnt be using with these chat bots?

This doens’t matter if your hosting provider disallows running these sorts of services.

I rent services from three different providers. And one of them flat disallows IRC bots/services/eggdrop/etc. So they won’t unblock the port or appreciate bypassing that block.

You connect ot Twitch Chat on the IRC or websocket standard ports. So even if one of those ports work, you would be violating your providers TOS.

Those ports are listed here - Chat & Chatbots | Twitch Developers

1 Like

Awesome. I will reach out to them and see what I can find out. Thank you!

I reached out and they say their hosting allows for IRC services. I asked about ports 80 and 443, which they said are just fine to use. Kind of at a loss here.

Could I be using the wrong authentication method? The app doesnt utilize any user input - it just reads chat and updates the website (it’s a chart that intakes votes). I generated an oauth token using Twitch Chat Password Generator but I’m guessing that is not the correct way to do it. I just dont know how I can launch this flask app that requires no user input, listens for chat, and updates the page.

I see that you posted this tool a while back:


Token is valid

client_id redacted
login redacted
scopes * channel:moderate
  • channel_editor
  • chat:edit
  • chat:read
  • whispers:edit
  • whispers:read|

Token is type “User Access”

This Tokens Twitch Profile from Helix:

id redacted
login redacted
display_name redacted
description just another bot
profile_image_url redacted
view_count 0
created_at 2022-11-22T23:43:22Z

This wouldn’t result in a connection error

This error says you failed to connect to the server.

It doesn’t provide any diagnostics as to why.

So you need to trace and solve that

Turns out it was the port. The twitch-python library is set to 6667. I went into the lib and changed it to 80 and the messages are coming in now just fine. Now I need to figure out how to get my sockio to work T_T. Thanks for the help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.