Forums

IRC Bot Can't Connect

I have an IRC bot (made specifically for twitch.tv) written in Python. It seems to work perfectly fine on my PC but when trying to run it on PythonAnywhere, it gives me this error:

Traceback (most recent call last):
  File "/home/Log/main.py", line 66, in <module>
    con.connect((HOST, PORT))
ConnectionRefusedError: [Errno 111] Connection refused

I don't understand why it would not work here but works fine on my computer. Please could somebody help me with this issue?

Thank you in advance.

EDIT: It also says there is a syntax error but when I use the code in IDLE, it says that I do not have any syntax errors. syntax error

EDIT: I've just discovered the whitelist. The server I'm connecting to is irc.twitch.tv:6667. I can't find this server on the list and I'm assuming that is the reason why this is not working. If I upgrade to the Hacker plan (as I am currently a free user), will this work? Considering that the code runs perfectly fine in Python's IDLE (3.4.0).

Thanks.

If you upgrade you'll be able to access the URL. But you could also request that it be added to the whitelist, by asking the PA folk. They require that the site has a published API - does it?

Thanks for your reply. Twitch does have an API and the API is actually on the whitelist (api.twitch.tv) but I need to connect to the IRC server, which is different (irc.twitch.tv).

I've heard that this site has "a no-quibble 30-day money-back guarantee." So I suppose upgrading to the Hacker plan won't hurt. It's probably less hassle.

I'll upgrade and try it out. If it doesn't work then I will try contacting them.

Thanks.

Sounds good. The site says:

All of our paid plans come with a no-quibble 30-day money-back guarantee — you're billed monthly and you can cancel at any time. The minimum contract length is just one month. You get unrestricted Internet access from your applications, unlimited in-browser Python, Bash and database consoles, and full SSH access to your account. All accounts (including free ones) have screen-sharing with other PythonAnywhere accounts, and free SSL support (though you'll need to get a certificate for your own domains).

Thank you very much for your help. I just upgraded to the Hacker plan and everything is working perfectly! :D

Good to know!

Jim

@Log -- thanks for upgrading!

The problem with the initial code is that you were making a non-HTTP request. We only allow HTTP (and HTTPS, of course) access to whitelisted sites.

(As an aside -- if I remember correctly it was actually IRC connections that made us first start realising that we needed to limit network access for free accounts. Someone was using us to spam or otherwise abuse an IRC channel, and the channel's owners were reporting the abuse to us and to AWS, our provider. We'd find the PythonAnywhere account they were using, and shut it down, but they'd just pop up again on another free account, using a different email address. That, plus a number of complaints about people DoSing small sites with huge numbers of HTTP requests, was what made us realise that any part of the service that people can sign up for without some kind of verification that they're not a known bad actor, was what led to the whitelist idea.)

Ah, ok. Thank you very much!

And I promise that I'm not abusing any IRC channels. It's simply to run a chat bot I made in a few small Twitch channels.

The only reason I looked for a service like this was so that I could have it running 24/7 without leaving my PC on.

Thanks for the information!

No problem!

Hi,

Can you please add *.freenode.net (with * meaning any subdomain) to the list too? I can assure you I will not spam freenode, I just intend to put a helper bot which will run 24/7 in a specific channel (which I created and I operate). Bot abusers will be taken care by me.

Thanks in advance.

That won't help -- we only allow HTTP and HTTPS access to whitelisted sites, not access using IRC's protocol.

How are they distinguished when connecting from a python script? Do HTTP accesses use different python calls?

The way the whitelist works is that the Python code connects to a proxy server, which then only allows access to go through for whitelisted sites. This is normally transparent to your code -- most modern Python HTTP libraries look at the system environment variables for HTTP/HTTPS proxy setup variables, and use them.

So for a free account, there's essentially a firewall that doesn't allow anything out unless it's to the proxy, or SSH to github or BitBucket.