Python Forum
A lot of confusion and I can't seem to solve this issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A lot of confusion and I can't seem to solve this issue
#8
(Jul-24-2022, 05:36 PM)snippsat Wrote:
(Jul-24-2022, 04:55 PM)Calli Wrote: This is working fine but how do you loop through all the ip which is in a file?
When you do this it will just be one big string object,that you can not iterate over.
Have to spilt it up for this to work.
ip_list = file_read.read()
Let say this is content.
ip_lst1.txt
Output:
118.31.106.59 118.31.106.59 118.31.106.59
Can just iterated over file object,no need to read()(and split it up).
import requests

with open('ip_lst1.txt') as f:
    for ip in f:
        ip = ip.strip()
        print(ip)
        response = requests.get(f"http://{ip}:9200/_cat/indices")
        print(response.text.strip())
Output:
118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb 118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb 118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb
Doing most task will be will be a struggle if you don't spend time learning📜 basic Python.

I'm learning python for beginner but it might take some time for be to be professional like you.. But I'm getting this error

124.221.82.115
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 158, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 597, in urlopen
    httplib_response = self._make_request(conn, method, url,
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 181, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 167, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f96018eaf50>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 637, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "/usr/local/lib/python3.10/dist-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='124.221.82.115', port=9200): Max retries exceeded with url: /_cat/indices (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f96018eaf50>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/media/computer/IP/scan.py", line 7, in <module>
    response = requests.get(f"http://{ip}:9200/_cat/indices")
  File "/usr/local/lib/python3.10/dist-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='124.221.82.115', port=9200): Max retries exceeded with url: /_cat/indices (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f96018eaf50>: Failed to establish a new connection: [Errno 111] Connection refused'))
IP
124.221.82.115
type Connection refused
can we add an exception or??
Reply


Messages In This Thread
RE: A lot of confusion and I can't seem to solve this issue - by Calli - Jul-24-2022, 07:24 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020