Requests - Python - Failed to establish a new connection: [Errno 111] Connection refused - python

I have a server running in Ubuntu OS, and I am using Python for getting to learn.
I started an app which I installed, When I opened the app in browser the page is not secure, like this -
I am getting some data from this page using python -
from urllib3.exceptions import InsecureRequestWarning
import requests
requests.urllib3.disable_warnings(category=InsecureRequestWarning)
req = requests.get(url='https://127.0.0.1:7001', verify=False)
This shows an error -
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='127.0.0.1', port=7001): Max retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc2ae5f94f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
When I print the variable req to check the status, but python shows the variable is not defined
How to solve this, thanks

HTTPSConnectionPool(host='127.0.0.1', port=443)
443 is the default port for HTTPS.
You're probably (we can't see how you've defined url, but that's my best guess) trying https://127.0.0.1/..., not https://127.0.0.1:7001/... – fix that in your code.

Related

New Connection Error when trying to use requests.get at python 3.7

well i've been trying to download a File directly from a URL, the thing is, when I do it at home it works perfectly fine, but when I try to run it at my company's server it doesn't work.
My code is:
import requests
url = "https://servicos.ibama.gov.br/ctf/publico/areasembargadas/downloadListaAreasEmbargadas.php"
response = requests.get(url, verify=False)
url = open("teste.zip", "w")
url.write(response.content)
url.close()
and the error message that i get is:
HTTPSConnectionPool(host='servicos.ibama.gov.br', port=443): Max retries exceeded with url: /ctf/publico/areasembargadas/downloadListaAreasEmbargadas.php (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001F2F792C0F0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
I konw that we use proxy here, i've been looking for solutions for this problem and I could see that this is relevant, but I couldn't find something to do with this information

Use Influxdb client in python - Error : 'InfluxDBClient' object has no attribute 'create_database'/' get_list_database '

I just started using the influxdb client in python. I'm probably doing something wrong but I can't figure it out yet.
from influxdb import InfluxDBClient, DataFrameClient
client=InfluxDBClient(host="localhost",port="8086", username='root')
client.create_database("TEST")
I get the following errors:
ConnectionError: HTTPConnectionPool(host='localhost', port=8086): Max retries exceeded with url: /query?q=CREATE+DATABASE+%22TEST%22 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000013E5DD0A8C8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Could you please tell me what I'm doing wrong ? Also is there a command line that I can use to know what's my token/url or what's the token/url of a remote host I would like to access.
Thanks
you are making a mistake while importing.
InfluxDBClient should be imported from influxdb.
like:
from influxdb import InfluxDBClient
also, constructor InfluxDBClient() takes no argument named url and token.
as per the doc, the constructor is:
InfluxDBClient(host='mydomain.com', port=8086, username='myuser', password='mypass', ssl=True, verify_ssl=True)
so your code should be like this:
from influxdb import InfluxDBClient, DataFrameClient
client=InfluxDBClient(host="localhost",port="8086", username='root')
client.create_database("TEST")
client.get_list_database()

Failed to establish a new connection using python winrm

When trying to connect multiple instances in a given CIDR range using python winrm. We are getting the following exception.
import wimrm
url = "http://10.24.x.x:5985/wsman"
username = admin#domain.com
password = xxxx
session = winrm.Session(url, auth=(username, password), transport='ntlm', server_cert_validation = 'ignore')
EXCEPTION HTTPConnectionPool(host='10.24.x.x', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10055] An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full'))
When tried connecting to a single server we were able to connect it. Would appreciate if provided with a solution.
Python 3.6
pywinrm 0.3.0

Connection refused Django requests-module

i'm trying to send GET request from my Django app to Spring app hosted in my local machine.
I've tested sending requests to another websites outside localhost and it works perfectly. Problem appears when it comes to sending to http://localhost:port.
This is function which is sending requests in my Django app. It works for url1 but doesnt for url2.
def send_mail(request):
url1 = "https://httpbin.org/get"
url2 = "http://localhost:5000"
response = requests.get(url2)
return HttpResponse(response)
Here's an error that shows wherever i try send request to localhost.
HTTPConnectionPool(host='localhost', port=5000): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused'))

how to go to a specific path of host using Python Requests?

I have this host: http://retsau.torontomls.net:7890/and I want to access http://retsau.torontomls.net:7890/rets-treb3pv/server/login, how can I accomplish this using Python Requests? All my attempts till now have failed.
I also followed the solution here - Python Requests - Use navigate site by servers IP and came up with this -
response = requests.get(http://206.152.41.279/rets-treb3pv/server/login, headers={'Host': retsau.torontomls.net})
but that resulted in this error:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='206.152.41.279', port=80): Max retries exceeded with url: /rets-treb3pv/server/login (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10a4f6d84>: Failed to establish a new connection: [Errno 60] Operation timed out',))
Funny thing is everything seems to work perfectly fine on Postman, I am able to access all sorts of URLs on that server, from logging in to searching for something.
You left out the port number (7890) from the URL to your get call:
response = requests.get('http://206.152.41.279:7890/rets-treb3pv/server/login', headers={'Host': 'retsau.torontomls.net'})
# ^^^^ Add this
Also, unless you actually have a specific reason for accessing the site by IP address, it would make more sense to put the FQDN in the URL rather than the Host header:
response = requests.get('http://retsau.torontomls.net:7890/rets-treb3pv/server/login')

Categories

Resources