1

Can Someone Please Tell me what's wrong with my piece of code

#! /usr/bin/python3
import subprocess
import os

class NmapPy():
    def __init__(self, command=[]):
        self.command=command

    def scan(self):
        try:
            p=subprocess.Popen(self.command, shell=False,
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            out,err=p.communicate()
            print("\n Nmap scan is complete : ")
            print(str(out))
            print(str(err))
        except Exception as ex:
            print("Exception caught : "+str(ex))

nmap=NmapPy(["nmap", "-Pn", "-sV", "127.0.0.1"])
nmap.scan()

when I run this script, this is the error I keep getting.. help!

Exception caught :partially initialized module 'subprocess' has no attribute 'Popen' (most likely due to a circular import)
Exception caught : module 'subprocess' has no attribute 'Popen'

1 Answer 1

4

I suppose something is shadowing subprocess module. Try to do

import subprocess
subprocess.__file__
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Alex, I found the file that was shadowing the subprocess module and I was able to resolve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.