Python Forum
Receiving this error in my "response" and causes script to return wrong status
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Receiving this error in my "response" and causes script to return wrong status
#13
readlines() splits it into separate lines,but also add new line \n.
Change to this.
with open("ip_list.txt") as file:
    park = [ip.strip() for ip in file]
Or in your first post you try to scan a folder for ip_list text files,then it can be done something like this.
import time
import subprocess
from concurrent.futures import ThreadPoolExecutor
import pandas as pd
import os

def ping(ip):
    return (
        ip,
        subprocess.run(
            f"ping {ip} -n 1", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
        ).returncode,
    )
start = time.time()

def scan_files():
    directory = '.'
    for entry in os.scandir(directory):
        if entry.is_file() and entry.name.endswith('.txt'):
            if 'ip_list' in entry.name:
                pt = directory + '/' + entry.name
                with open(pt) as file:
                    for ip in file:
                        yield ip.strip()

executor = ThreadPoolExecutor(5)
df = pd.DataFrame(executor.map(ping, list(scan_files())))
df.to_csv(r'ip_output.csv',header=False, index=False, quoting=None)
print(df)
Reply


Messages In This Thread
RE: Receiving this error in my "response" and causes script to return wrong status - by snippsat - Aug-12-2023, 06:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,416 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,722 Mar-27-2023, 07:38 AM
Last Post: buran
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,776 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 1,517 Jul-31-2022, 08:20 PM
Last Post: paulyan
  Receiving snmp traps with more than one Community String ilknurg 0 2,315 Jan-19-2022, 09:02 AM
Last Post: ilknurg
  return out of loops syntax error felixf 7 3,555 Nov-03-2020, 01:00 PM
Last Post: perfringo
  ERROR: Command errored out with exit status 1 calesii 3 7,285 Oct-23-2020, 05:39 PM
Last Post: snippsat
  SystemError: error return without exception set!!! faryad13 3 3,847 Oct-23-2020, 02:32 PM
Last Post: ATARI_LIVE
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,797 Sep-28-2020, 07:57 AM
Last Post: buran
  Empty response to request causing .json() to error t4keheart 1 10,270 Jun-26-2020, 08:35 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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