Errno::ECONNREFUSED (Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)) - ruby

I'm trying to use the library HTTParty, but whenever I run the code below I receive an error.
Code:
require 'httparty'
response = HTTParty.get('http://example.com')
When I run the code I receive the error: Errno::ECONNREFUSED (Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)).
I don't get any error when I run the same code in net/http. I don't know if this helps, but the system I'm running is Linux Mint 18.3 Cinnamon 64-bit .

I know that this is late, but using https://example.com instead of http://example.com was the solution to my problem.

Related

XAMPP receives "Connection refused" when curling other localhosts

I've a Reactjs app (NodeJS) running on localhost:3000 as well as a local blockchain node (Hardhat) running on localhost:8545.
There's no issues with those two communicating with each other, but I also have a XAMPP server running locally on localhost:8080 with a php app that returns some values.
I can reach all these localhosts fine through the browser.
But I need the php to communicate with my blockchain node. But the connection keeps getting refused when Xampp tries to create the connection to the node.
I even tried a basic curl from Xampp's terminal, and Xampp can't reach the other localhosts at all (tried both http://localhost:port and http://127.0.0.1:port). For instance if I just wanted to curl my react app (html) from Xampp's terminal like this...
curl http://localhost:3000/ -v
I get this...
* Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 3000 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused
Yes, I can curl things like google.com fine from within Xampp's terminal with no issues. It's just my localhosts. Yes, I have enabled curling in php. Yes, I can curl my react app (html) just fine from a separate terminal window. I'm on MacOS 12.1.
Thanks in advance for any help!!
Edit: I did some research, and I believe the issue is that the Xampp virtual machine can't reach my localhost. I've tried resolving this at the host file level to redirect a domain name to 127.0.0.1, but that doesn't work either. I'm still stuck, but wanted to put an update in case this info is helpful.
Last edit: I gave up.

Connection refused on port 80 on Laravel Valet site

I've been trying get my Laravel Valet to work again (after working with Vagrant and vue-cli it stopped working). Have resinstalled it many times. Nothing else is running on port :80, and it doesn't help when changing the port to something else.
(But maybe been doing it wrong?)
When I'm running
curl -IL http://example.test/
I get "curl: (7) Failed to connect to example.test port 80: Connection refused"
Any ideas how to proceed?

Accessing PhpMyAdmin On Mac OS High Sierra w/ Amazon Lightsail

I am trying to access PhpMyAdmin on my browser through an SSH tunnel on mac OS high sierra for setting up AWS Lightsail. I've downloaded my default SSH key pair and have adjusted permissions using
chmod 600 KEYNAME.PEM
I've tried ports 80 and 81 and have tried using port 1025. I do not get any errors in Terminal, but when launching via the URL: http://127.0.0.1:8888/phpmyadmin as suggested in Bitnami docs (with port adjusted to 1025 if 1025 is running), I get the error: "This site can’t be reached
127.0.0.1 refused to connect." and in Terminal: "channel 2: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused
channel 2: open failed: connect failed: Connection refused
channel 3: open failed: connect failed: Connection refused"
I'm using Google Chrome, 64-bit. I've tried turning firewall off, as well.
Any suggestions would be greatly appreciated! I'm new at this. Thank you!
I figured it out! I'm not sure what did it, but I added a slash at the end of the URL I was accessing, i.e. localhost:8888/phpmyadmin/ instead of localhost:8888/phpmyadmin. I also installed Cyberduck for mac and turned started/stopped my local servers with MAMP. Hoping this is helpful for someone else.

Ruby socket connection refused on 0.0.0.0:8080

I'am learning ruby socket programming and I'am on linux OS(Ubuntu 16.04 to be exact).
The following code:
require 'socket'
socket = TCPSocket.new('0.0.0.0', 8080)
client = socket.accept
puts "New client! #{client}"
client.write("Hello from server")
client.close
is giving me the following error:
sock2.rb:3:in initialize': Connection refused - connect(2) for "0.0.0.0" port 8080 (Errno::ECONNREFUSED)
from sock2.rb:3:innew'
from sock2.rb:3:in `'
Should I use a different IP and port? or do I have to make some sort of configuration on my unix system for the client and server to speak to each other.
TCPSocket.new tries to connect to the host specified in the arguments. It looks like you are trying to set up a server listening on that port, for that you should use TCPServer instead:
socket = TCPServer.new('0.0.0.0', 8080)
You can then connect to this server with another client. That client could possibly use TCPSocket.

ftp - connection refused on Mac

If I run ftp localhost on Mac terminal, it shows the following result.
Trying ::1...
ftp: Can't connect to `::1': Connection refused
Trying 127.0.0.1...
ftp: Can't connect to `127.0.0.1': Connection refused
ftp: Can't connect to `localhost'
I already have apache installed on Mac, and I checked that out by entering localhost on the browser.
How do you diagnose this matter, and what should I take for the next step?
PS some people might ask me about the firewall. I checked that out as well in the system preferences and it's off.

Resources