Python subprocess Help - python

I'm testing python subprocess and I keep getting this error:
$ python subprocess-test.py
Traceback (most recent call last):
File "subprocess-test.py", line 3, in <module>
p = subprocess.Popen(['rsync', '-azP', 'rsync://cdimage.ubuntu.com/cdimage/daily-live/current/maverick-desktop-amd64.iso', '/home/roaksoax/Desktop/iso'], stdout=subprocess.PIPE)
AttributeError: 'module' object has no attribute 'Popen'
My script is:
import subprocess
p = subprocess.Popen(['rsync', '-azP', 'rsync://cdimage.ubuntu.com/cdimage/daily-live/current/maverick-desktop-amd64.iso', '/home/testing/maverick.iso'], stdout=subprocess.PIPE)
Do you guys know what might be happening?

Wild guess: you have your own file called subprocess.py which is masking the standard library module.
What do you see with this?:
import subprocess
print subprocess.__file__
This will show what file is being imported as subprocess.

Related

I am not able to use re module, my interpreter showing me error

My code is:
import re
s="An apple in a day."
print(re.search("in",s))
Error:
C:\Users\DELL\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py
Traceback (most recent call last):
File "C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py", line 1, in <module>
import re
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\Lib\encodings\re.py", line 3, in <module>
re.search("is",s)
AttributeError: partially initialized module 're' has no attribute 'search' (most likely due to a circular import)
Process finished with exit code 1
You name your file re.py so python confused which one to use when you call import re: your file or regexp library.
Try to rename your file to something else and not to choose other library names.

How to specify the process in python pwntools?

Cant set the process in Python 2.7.17 pwntools.
Source code:
from pwn import *
s=process('/root/Dokumente/Scripts/example_program')
I tried from pwn import *:
root#bitpc:~# python pwn.py
Traceback (most recent call last):
File "pwn.py", line 1, in <module>
from pwn import *
File "/root/pwn.py", line 2, in <module>
s=process('/root/Dokumente/Scripts/example_program')
NameError: name 'process' is not defined
That was not working. Then i imported process directly:
root#bitpc:~# python pwn.py
Traceback (most recent call last):
File "pwn.py", line 1, in <module>
from pwn import process
File "/root/pwn.py", line 1, in <module>
from pwn import process
ImportError: cannot import name process
I got an import error. How to fix this?
It seems that your exploit script's name is pwn.py. rename it to some other name such as exp.py. otherwise python will try to import things in your pwn.py instead of importing things from pwntools.

os.command giving Attribute error

Hi I am trying to rum a C *.o using python 2.6.5 as follows
import os
import sys
file_type = os.command('./file_type.o %s.txt 2>&1' % file_name)
And, it gives the error message :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'command'
Being a beginner this might be a very trivial question, I request for the direction / help.
There is no function named command in the os module, hence the error. You probably meant to call os.system() instead.
os.command() doesn't exist. It looks like you are looking for os.system()
os.command doesn't exist, using os.system instead.

Python os.remove failure (unicode object?)

My python script reads JSON information from a website, stores it in a file for processing, and should clean it in the end.
This was working without issues in other scripts, but for some reason, os.remove fails to delete the file in the end:
import urllib2, json
import os, sys, argparse
ref_list_tmpfile = '/tmp/reference.%s.txt' % os.getpid()
ref_list_response=urllib2.urlopen('http://localhost:11111/api/reference').read()
with open(ref_list_tmpfile,'w') as outfile:
outfile.write(ref_list_response)
ref_list_data=open(ref_list_tmpfile)
reference_list = json.load(ref_list_data)
ref_list_data.close()
.
.
.
.
os.remove(ref_list_tmpfile)
The main logic works well, but the error i'm getting refers to the last command (os.remove) and the file is not deleted:
Traceback (most recent call last):
File "./vm_creator.py", line 58, in <module>
os.remove(ref_list_tmpfile)
AttributeError: 'unicode' object has no attribute 'remove'
Any ideas?
You've redefined os to be a string, somewhere in the code you've snipped.

AttributeError 'module' has no attribute 'Queue"

I am trying to import Queue and I keep getting the following
Traceback (most recent call last):
File "threading.py", line 2, in <module>
import Queue
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/Queue.py", line 5, in <module>
import threading as _threading
File "/Users/zaq/threading.py", line 10, in <module>
queue = Queue.Queue()
AttributeError: 'module' object has no attribute 'Queue'
I am using the code in the link Threading in python using queue
Also, I can import and use Queue in the python interpreter.
What am I doing wrong?
Name of my script was threading.py... Changed it and everthing works fine. Rookie mistake.

Categories