Forums

ConnectionRefusedError: [Errno 111] Connection refused

Hello, Im a free user and want to use python and connect with freelancer.com website using freelancer sdk. I get this error. is not freelancer.com whitelisted? ConnectionRefusedError: [Errno 111] Connection refused

No, it's not whitelisted, but if you can give us a link to their API documentation then we can whitelist it.

Thank you for your quick response. here is documentation link: https://developers.freelancer.com how soon can it be whitelisted? week,month,year?

It's whitelisted now :-)

thank you :)

one more question. I try to connect with freelancer with script and error says this : Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 141, in _new_conn (self.host, self.port), self.timeout, **extra_kw) File "/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py", line 83, in create_connection raise err File "/usr/local/lib/python3.6/dist-packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

is this problem of whitelisting or something else? sorry if question is nonsense cause Im really newbie . :)

It's related to whitelisting, yes. When you want to access an external website from a free account, you need to go via a proxy. Modern HTTP libraries like requests will do that automatically (they detect the proxy settings from the environment), but some (like urllib3) need extra configuration. If you're writing the code to connect to freelancer yourself, just use requests.get and it should work fine.

Thank you again for so helpful answer. as I'm not writing it and using freelance sdk which uses urllib3, I would be glad if you could tell me where to find info how to configure it. is there any thread on your website about this?

I think you're the first person to use the SDK on our site; if you look at their documentation, though, they should have an explanation of how to use it with a proxy -- you'll have to somehow specify a proxy hostname and port. You can find out what values to use from those by doing echo $http_proxy in a bash console. The result will be something like http://proxy.server:3128, which means that the servername is proxy.server and the port is 3128.

Thank you! case closed :)

:-)

Hi, I also got the same error code when trying to connect to Beams PUSHER https://pusher.com/ and using their python SDK. I'm not sure if it's related to this topic too. It works when I request a token but failed to send the notification. Thank you for the help!

I checked the list and it is on the whitelist. So if anyone can help why the error occurred would be very thank you!

What code are you using to connect to it? Is it an API module that someone else has written, or your own code using an HTTP library? If it's the latter, try using requests rather than (say) urllib2 -- requests to whitelisted sites have to go via a proxy, and requests will handle that automatically for you, whereas the built-in libraries need special configuration.

Hi! I use the API module in the SDK and I also asked the developer team. They don't think the proxy is the issue. The domain format they use in this SDK is as below: "<INSTANCE_ID>.pushnotifications.pusher.com". The domain ".pusher.com" is whitelisted, but is the above domain also whitelisted or only support single layer of the subdomain?

Thank you for all the help!

The URL <INSTANCE_ID>.pushnotifications.pusher.com is on the whitelist because of the .pusher.com entry.

I have the same problem. I am connecting to the Minecraft server Nox.gs via the mcstatus library but get the same error. I can't rewrite the library.

That's not on the whitelist, so rewriting the library will not help, anyway.

@glenn so what do I do?

If there's a public API for the data that you're trying to access, then send us a link to the documentation for that API and we can add it.

https://pypi.org/project/mcstatus/. Here, this library pings a certain Minecraft server and shows you stats. However, it can't connect in PythonAnywhere.

What we need is public documentation for the minecraft server that shows that the administrators of the server are happy for their site to be used by libraries like mcstatus.

Here's the documentation: https://github.com/Dinnerbone/mcstatus

This library simply pings the Minecraft server and tells how many players are in. It's nothing more than entering Minecraft and looking it up there. "mcstatus provides an easy way to query Minecraft servers for any information they can expose. "

Also, the library is written by Minecraft dev. It simply connects to their servers and takes VISIBLE info.

None of that constitutes public documentation for the use of the API on Nox.gs. Without that, we do not know if the administrators of the site are happy for you to be hitting it using a program.

Fine, I'll ask the admin. And it's not "hitting" them, since it's the same as opening Minecraft and doing the same manually.

hitting just means making a http request and getting a http response

And what's the problem with that? If I write a game and then make a program that scans certain things in the game, I am allowed to since it's my game. Same goes for a library written by the game dev. Plus I am doing it on my own computer (but of course it can't run 24/7), so there is no difference, AND it's not such a big deal, a tiny ping every 5 minutes.

If we whitelist something, any free user can access it. So while your own program might be accessing the site responsibly, hackers could use our systems to attack it. They would not be traceable if they were using free accounts, so we could wind up being blamed.

So in theory, we should block all outbound Internet access for free accounts. However, we take the view that if the owner of a site has officially stated that it's OK for people to connect to their site using an API, they are aware of the risks and can handle any attacks themselves -- so we under those circumstances we can whitelist the site in question.

Oh.

Ok, I've asked the server owner and he said he'll talk to you.

I have received a positive answer from the admin, which says he talked to you, but still doesn't work. MinecraftServer.lookup("noxcrewfactory.com") doesn't work.

Can you fix this please? I have permission

I can't find anything relating to noxcrewfactory.com in our tech support archives, so I don't think the admin of that site has been in touch with us.

hi i have the connection refused when try to expand shortlinks from amazon https://amzn.to/xxx or http://amzla.com/xxxx, is in whitelist?

If you provide the api endpoint documentation we can consider adding it to the whitelist.

is not for api connection, is only a query to know the long link from a shortened link

We can only whitelist sites that are official documented public APIs.

Hello. I'm getting the same connection refused error when using pythonopensubtitles to pull subtitles from opensubtitles.org. The website's API documentation is here https://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC . Can you please see if this site can be whitelisted as well?

We do have api.opensubtitles.org on the whitelist, so it sounds like the package you're using does not pay attention to the proxy settings in the system environment, and is trying to connect to the site directly. You'll have to find out how to get the package to work with a proxy -- I took a look around on their github page, but unfortunately there's nothing obvious there about how to do that.

Hello @giles, i have the same 111 Error, this time I am trying to use Telegram's API with this https://docs.pyrogram.org/.

Hi. same [Errno 111] problem with pyrogram(Telegram API). https://docs.pyrogram.org/

@danielqba that sounds strange -- you have a paid account, so you have unrestricted Internet access. Your code can connect directly to Telegram's API without going through any of our firewall systems. Could you post the code you're using (without any passwords, of course)?

@88matin88 -- you have a free account, so you can only make outwards connections using HTTP or HTTPS, to whitelisted sites, so I don't think you can use the MTProto API, which doesn't use HTTP or HTTPS -- it has its own protocol.

@giles, nevermind, that was before I got a paid account. :)

Thanks for letting us know!

Hello, I am a new user and so far using free account. Trying to access XTB.com API but getting a Connection Refused Error. Here is theirs documentation -> http://developers.xstore.pro/documentation/.

Could you please suggest, should I move to paid account to be able to connect it or xib.com just needs to be added in whitelist?

It looks like that API is not based on HTTP or HTTPS, so it won't work from a free account -- whitelisted sites can only be accessed using those protocols, not raw socket connections.

From a paid account, you would have unrestricted Internet access and could connect to any site that allows connections, using any protocol.

Hello, I am a new user using a free account. I am using an AWS DB yet my connections are getting refused, could you please suggest what I should do next to ensure my connections are successful. I ran the same code locally and the connections have been succesful.

This is a follow up from a question I just asked, I just checked the whitelist and confirmed amazonaws.com is on it yet I am still getting my connection refused.

Thank you

Could you share your code and the error message you are getting?

Hello i have the same error of ConnectionRefusedError: [Errno 111] Connection refused

@RayDraw that's likely because you're using a free account which has restricted internet access to whitelisted domains.

Hello, Im a free user and want to use python and connect with outlook smtp server . I get this error.... ConnectionRefusedError: [Errno 111] Connection refused. Is not 'smtp-mail.outlook.com' whitelisted?

See https://help.pythonanywhere.com/pages/SMTPForFreeUsers/

Ciao ho creato la mia webapp con python e flask l'ho caricata correttamente su python everywhere ma quando avvio il software mi da errore 111 requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8001): Max retries exceeded with url: /chain (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fce8f6dd550>: Failed to establish a new connection: [Errno 111] Connection refused') non so proprio cosa fare, help me

There is not and never really will be a server running on 127.0.0.1:8001, so you will never be able to connect to it.

Is there any restriction on accessing any website for paid plans as well?

Paid accounts have unrestricted internet access on PythonAnywhere, which means that there are no restrictions for outgoing connections.

Hello, Im a free user and I am trying to get information about my minecraft server with mcstatus (https://pypi.org/project/mcstatus/), but I get error "ConnectionRefusedError".

Could you provide the full error message, including the stack trace?

hello i am getting error: File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused

please help, I set up sending and it works locally for me. Here are my settings. EMAIL_HOST = 'smtp.sendgrid.net' EMAIL_HOST_USER = 'apikey' EMAIL_HOST_PASSWORD = os.getenv("SENDGRID_API_KEY") EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' DEFAULT_FROM_EMAIL = os.getenv("EXCHANGE_OF_INVOICES_EMAIL")

Are you sure that your environment variables are correctly populating your settings and you do not have None there?

I wasn't sure about everything. of course I checked the environment variables. I copied the .env file to the server to prevent incorrect key entry.
I tried this:
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = os.getenv("EXCHANGE_OF_INVOICES_EMAIL")
EMAIL_HOST_PASSWORD = os.getenv("API_KEY")
EMAIL_PORT = 587
EMAIL_USE_TLS = True
instead of:
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = os.getenv("SENDGRID_API_KEY")
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = os.getenv("EXCHANGE_OF_INVOICES_EMAIL")
Both methods work in the local machine. but the second way doesn't work in "pythonanywhere"

Is your .env loaded to environemnt? See https://help.pythonanywhere.com/pages/environment-variables-for-web-apps

i user free in PythonAnywhere and make web with Django i have code for make connecting with mikrotik router code run with local sever but give me [Errno 111] Connection refused can help me

How do you try to reach your router?

From routers_api lib

Is it visible in the public internet?

Yes and it working in local hoat in my pc And don't working in pythonanywhere This code

import routeros_api
connection = routeros_api.RouterOsApiPool(
                    host=device.host,
                    username=device.username,
                    password=device.password,
                    port=8728,
                    use_ssl=False,
                    ssl_verify=False,
                    ssl_verify_hostname=True,
                    ssl_context=None,
                    plaintext_login=True
                )
api = connection.get_api()

Free accounts have restricted internet access, so you would not be able to connect with an external device like that.

Hello,

Could you please let me know if I can use pandas_datareader with my free account? I'm copying the error that I'm getting below.

Error running WSGI application pandas_datareader._utils.RemoteDataError: Error connecting to 'ftp.nasdaqtrader.com': [Errno 111] Connection refused

Thanks

You will not be able to use FTP to a service outside of PythonAnywhere from a free account.

Hello, I m a free user and want to use python and connect with Telegram Api. I get this error, ConnectionRefusedError: [Errno 111] Connection refused. I was working for some time but then this happened. Please help.

Can you share your code please?

Sure, here is the code.

import requests
import pandas as pd

How are you running this code on PythonAnywhere? Do I understand correctly that it was working for some time on PythonAnywhere and then you couldn't make it work anymore without any changes in the code?

Its an ongoing code. it is always looking for new message to read in telegram bot. I made it run and closed it. For few hours( around 10 to 12 hrs) it was working fine. But around midnight it stopped and showed this error. ConnectionRefusedError: [Errno 111] Connection refused.

Could you provide the full error message, including the stack trace?

I don't have it now dear. I just copied the first error and pasted it here. When I re-run the code, it started working again. What should I do now ?

Do you have timestamps when it was not working?

No dear, I don't have any time stamps.

You need to add some logging to your code to get timestamps.

How to do that ? Can you please help me as I am a total beginner in python.

Here you go: https://help.pythonanywhere.com/pages/MySiteIsSlow/#adding-print-debugs-to-your-code

Today the tarpit closed my console, Idk why. it just closed it, Idk it was coz of some error or it just closed it anyway. my usage info : CPU Usage: You are in the tarpit. 100% used – 1087.67s of 100s. Resets in 1 hour

Also the timestamps code showed this error: print('{timestamp} -- request started'.format(timestamp=datetime.utcnow().isoformat()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma?

What do you mean by "closed it" -- did the console dissapear and was no longer on the console list, or did it just reset and reconnected, so you lost the running job/output of previous commands? Where do you see the "comma" error, is that in a new console? Could you show the full error message?

Yes, the console disappeared and was no longer on the console list. Yes , I lost the running job/output of previous commands.

the full error was when I pasted the code for Adding print debugs to my code :

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/bin/pythonanywhere_runner.py", line 26, in _pa_run code = compile(f.read(), filename.encode("utf8"), "exec") File "/home/lallodatu/Exp1.py", line 6 print('{timestamp} -- request started'.format(timestamp=datetime.utcnow().isoformat()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma?

From the output I guess that you've been running this console in the in-browser editor (by pressing the "Run" button). Could you try killing the current console (if you have one) and running your code again? Also -- mind that our consoles our ephemeral by design, if you need more persistent logging, please log into a file.

Yes I tried killing the current console and running the code again, it still shows the same error as above.

How to log into a file ? Also How can I make the code run forever for free ? The console keeps closing again and again. Your help on this will be much appreciated.

Also where can I have a chat with you (in real time)? I want to close this issue asap. Can you please provide me your sm id so that we can chat and clear it out ? Please ?

Here's how to log to a file -> https://docs.python.org/3/howto/logging.html

You can use Always-on tasks to run your code at all times. It is a paid feature though -> https://help.pythonanywhere.com/pages/AlwaysOnTasks/

Sorry we're not able to offer in-person support as we're quite a small team

I'm connecting to an external system (via the free account) and get the error

DEBUG:root:Attempting to connect to: https://xxxxx.papyrs.com/api/v1/pages/records/lkbL/ DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): xxxxx.papyrs.com:443 ERROR:root:Connection Error: HTTPSConnectionPool(host='xxxxx.papyrs.com', port=443): Max retries exceeded with url: /api/v1/pages/records/lkbL/ (Cau sed by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

Are there restrictions on the free account to access external resources? Do I need to authenticate on the proxy?

Free accounts are limited to accessing sites on our allowlist of official, documented public APIs. To access something that isn't in that category, you would need to upgrade to a paid account.

Ok thanks. That explains it