WinError 10061 - No Connection Could be made - python-3.x

I'm debugging a simple program, that has worked in the past. I've singled out the instruction where the error takes place, but I cannot figure out what triggers it. I've read all questions related to WinError 10061, but I do not see a clear answer
urllib.request.urlopen('http://www.wikipedia.org/')
Traceback (most recent call last):
File "C:\Python33\lib\urllib\request.py", line 1248, in do_open h.request(req.get_method(), req.selector, req.data, headers)
File "C:\Python33\lib\http\client.py", line 1061, in request self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1099, in _send_request self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1057, in endheaders self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 902, in _send_output self.send(msg)
File "C:\Python33\lib\http\client.py", line 840, in send self.connect()
File "C:\Python33\lib\http\client.py", line 818, in connect self.timeout, self.source_address)
File "C:\Python33\lib\socket.py", line 435, in create_connection raise err
File "C:\Python33\lib\socket.py", line 426, in create_connection sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
urllib.request.urlopen('http://www.wikipedia.org/')
File "C:\Python33\lib\urllib\request.py", line 156, in urlopen return opener.open(url, data, timeout)
File "C:\Python33\lib\urllib\request.py", line 469, in open response = self._open(req, data)
File "C:\Python33\lib\urllib\request.py", line 487, in _open '_open', req)
File "C:\Python33\lib\urllib\request.py", line 447, in _call_chain result = func(*args)
File "C:\Python33\lib\urllib\request.py", line 1268, in http_open return self.do_open(http.client.HTTPConnection, req)
File "C:\Python33\lib\urllib\request.py", line 1251, in do_open raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>
I run Python 3 in Windows 8. I tried turning off the firewall, as a couple of people suggested, but nothing changes. I also tried to add Python to the list of Apps allowed by the firewall. By the way the program line worked without any problem until a few days ago, when I deleted a few Apps from my PC.

It turned out the Internet Properties, Connection tab, LAN Settings were set to Proxy Server. I changed it to automatically detect settings, and everything restarted working correctly.

Edit Your Environment Variable Path. I had cntlm in my path, which was causing proxy issue.

Related

openssl unable to get local issuer certificate- but why do I need it?

I admit that I'm not a sysadmin by training, so I don't "get" some things that come up. This is one of those times.
I was setting up a server for a project. Stupidly, because the last time I'd been shoved into a sysadmin role I was working with Centos7, I opted for that OS out of familiarity. When installing Python 3.10+ (I specifically need 3.10+ for some packages I intend to use), openssl was an issue; after a certain version, 1.0.2 (the last shipped version with Centos7) is not an option, and I had to spot-setup 1.1.1k for this Python3 installation to work.
So I have this Python3.10 installation working:
python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.1.1k 25 Mar 2021
Now, I need to run queries against a remote postgres database's API using their Python3 sdk. I get openssl problems when I do. Minimum to reproduce:
from algosdk.v2client import indexer
indexer_url="https://mainnet-idx.algonode.cloud"
indexer_client = indexer.IndexerClient(indexer_token='', indexer_address=indexer_url)
indexer_client.search_assets(asset_id=0)
This fails:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/urllib/request.py", line 1348, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/local/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/lib/python3.10/http/client.py", line 1037, in _send_output
self.send(msg)
File "/usr/local/lib/python3.10/http/client.py", line 975, in send
self.connect()
File "/usr/local/lib/python3.10/http/client.py", line 1454, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/usr/local/lib/python3.10/ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "/usr/local/lib/python3.10/ssl.py", line 1071, in _create
self.do_handshake()
File "/usr/local/lib/python3.10/ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/site-packages/algosdk/v2client/indexer.py", line 801, in search_assets
return self.indexer_request("GET", req, query, **kwargs)
File "/usr/local/lib/python3.10/site-packages/algosdk/v2client/indexer.py", line 74, in indexer_request
resp = urlopen(req)
File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/usr/local/lib/python3.10/urllib/request.py", line 519, in open
response = self._open(req, data)
File "/usr/local/lib/python3.10/urllib/request.py", line 536, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/usr/local/lib/python3.10/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/local/lib/python3.10/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
Okay. My initial impression was that this could be a firewall issue, so I put my firewall down. No change. Put the firewall back up. (_ssl.c:997) seems to mean "Unable to get local issuer certificate", and trying to find a resolution brings me to sites like this one.
This is where I start to lose my patience, because I just don't understand the issue. I've only handled ssl certificates in the context of setting up a website; I put up a site, the site needs a signature specifying certain things about it (which earns it an s at the end of http), so I obtain a certificate it and tie it to the site. That's the extent of my understanding. I'm not talking about a website here. Yes, I'll be hosting a website on this server, but I'm literally just talking about a Python3 script. The error above seems to indicate that the issue is that I don't have an ssl certificate. Why does that matter? This code runs on my local machine, and I never had to obtain an ssl certificate.
tl;dr: help a noob out, please. I don't understand the problem, and that also means that I don't know what to look up to fix it.

Why Error urllib.error.ContentTooShortError:

I get this error while retrieving the program I wrote with kivy.
I have to use vpn
Downloading https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip
Traceback (most recent call last):
File "/home/mm/kivyenv/bin/buildozer", line 8, in <module>
sys.exit(main())
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/scripts/client.py", line 13, in main
Buildozer().run_command(sys.argv[1:])
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/__init__.py", line 1047, in run_command
self.target.run_commands(args)
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/target.py", line 92, in run_commands
func(args)
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/target.py", line 102, in cmd_debug
self.buildozer.prepare_for_build()
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/__init__.py", line 169, in prepare_for_build
self.target.install_platform()
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/targets/android.py", line 665, in install_platform
self._install_android_ndk()
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/targets/android.py", line 455, in _install_android_ndk
self.buildozer.download(url,
File "/home/mm/kivyenv/lib/python3.8/site-packages/buildozer/__init__.py", line 677, in download
urlretrieve(url, filename, report_hook)
File "/usr/lib/python3.8/urllib/request.py", line 1866, in retrieve
raise ContentTooShortError(
urllib.error.ContentTooShortError: <urlopen error retrieval incomplete: got only 261037633 out of 823376982 bytes>
From the urllib documentation:
exception urllib.error.ContentTooShortError(msg, content)
This exception is raised when the urlretrieve() function detects that the amount of the downloaded data is less than the expected amount (given by the Content-Length header). The content attribute stores the downloaded (and supposedly truncated) data.
In practice, it's likely that the VPN terminated the socket. You may need to implement retry/resume capability in your program.

Unable to docker-compose up any project

Whenever I try to docker-compose up any project I get the following error.
I've tried with and without sudo
I am only having this issue on this machine. I am able to run the same containers on my Mac and Amazon WorkSpace.
(myslabs) [austin#localhost myslabs]$ sudo docker-compose up
[sudo] password for austin:
Traceback (most recent call last):
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1252, in request
File "http/client.py", line 1298, in _send_request
File "http/client.py", line 1247, in endheaders
File "http/client.py", line 1026, in _send_output
File "http/client.py", line 966, in send
File "docker/transport/unixconn.py", line 43, in connect
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests/adapters.py", line 449, in send
File "urllib3/connectionpool.py", line 727, in urlopen
File "urllib3/util/retry.py", line 403, in increment
File "urllib3/packages/six.py", line 734, in reraise
File "urllib3/connectionpool.py", line 677, in urlopen
File "urllib3/connectionpool.py", line 392, in _make_request
File "http/client.py", line 1252, in request
File "http/client.py", line 1298, in _send_request
File "http/client.py", line 1247, in endheaders
File "http/client.py", line 1026, in _send_output
File "http/client.py", line 966, in send
File "docker/transport/unixconn.py", line 43, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "docker/api/client.py", line 205, in _retrieve_server_version
File "docker/api/daemon.py", line 181, in version
File "docker/utils/decorators.py", line 46, in inner
File "docker/api/client.py", line 228, in _get
File "requests/sessions.py", line 543, in get
File "requests/sessions.py", line 530, in request
File "requests/sessions.py", line 643, in send
File "requests/adapters.py", line 498, in send
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bin/docker-compose", line 3, in <module>
File "compose/cli/main.py", line 67, in main
File "compose/cli/main.py", line 123, in perform_command
File "compose/cli/command.py", line 69, in project_from_options
File "compose/cli/command.py", line 132, in get_project
File "compose/cli/docker_client.py", line 43, in get_client
File "compose/cli/docker_client.py", line 170, in docker_client
File "docker/api/client.py", line 188, in __init__
File "docker/api/client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))
[142201] Failed to execute script docker-compose
I've not been able to find any articles about any similar issues.
I am using Centos 8 running inside of a VirtualBox on Windows.
(myslabs) [austin#localhost myslabs]$ docker --version
Docker version 19.03.13, build 4484c46d9d
(myslabs) [austin#localhost myslabs]$ docker-compose --version
docker-compose version 1.27.3, build 4092ae5d
Any help would greatly be appreciated.
I also encountered the same error as you,My problem is that docker does not start.
check docker status systemctl status docker
systemctl start docker
docker-compose up try again
systemctl enable docker to start on boot
If you're on a Mac, it may mean that Docker itself isn't running. I had rebooted my Mac and Docker wasn't set to automatically launch at login. You can set this as a Docker preference.
If nothing works, run:
sudo chmod +x /usr/local/bin/docker-compose
sudo docker-compose up -d
If On WSL2 ensure that the docker service has been started, use sudo service docker status to check. If it is not running, use the command sudo service docker start to get it running before sudo docker-compose up
Sometimes docker service is stopped. You can check it and restart.Normally happens if error iscontainer. can pruine and start again.
Please restart docker containers and it will work fine.
This issue comes mainly in the case of windows. restart your docker container.
then run the docker command from your terminal

FileNotFoundError when using subprocess

from subprocess import check_output
output=check_output(["ls", "F:\myData\input"]).decode("utf8")
print(ouptut)
I'm trying to run this code to view the files in this directory and save the results as output but this line is throwing an error upon execution.
Can anyone help me solve this and understand the issue?
Traceback (most recent call last):
File "F:\myData\input\Analysis.py", line 21, in <module>
output=check_output(["ls", "F:\myData\input\Analysis.py]).decode("utf8")
File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

urllib.urlopen() gives socket error: Name or service not known on python2.7

I am just starting to use and learn Python, so this may seem vary naive to ask.
On my Linux system if i try to get a webpage using urllib.urlopen() I get an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
return opener.open(url)
File "/usr/lib/python2.7/urllib.py", line 207, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 344, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 776, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 757, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known
>>>
If I try to do the same in the Python 2.7 installed in my Windows 7 system, it works fine.
Since i am a novice, its difficult for me to diagnose the problem. I tried to research it but still haven't got any answers.
So my questions are:
What is different in the windows system that urlopen() works there but not on Linux.
What needs to be done to ensure that urlopen() works on the Linux system. Its necessary for me that it works since the the program I am developing has some bash command calls and the program depends extensively on the proper working of urllib.

Resources