I want to execute a Perl script using this Python code
def convert_to_excel(filename):
print('file name :' + filename)
pipe = subprocess.Popen(["perl", "./parse.pl", filename])
pipe.stdin.write(filename.encode('utf-8'))
pipe.stdin.close()
but I have this Error and this is my backtrace
file name :nessus_44_623890728.nessus
Traceback (most recent call last):
File "/root/PycharmProjects/Nessus/main.py", line 317, in <module>
convert_to_excel('nessus_44_623890728.nessus')
File "/root/PycharmProjects/Nessus/main.py", line 268, in
convert_to_excel
pipe.stdin.write(filename.encode('utf-8'))
AttributeError: 'NoneType' object has no attribute 'write'
Related
I am working on a channels attribution project in Python. I use the python library "ChannelAttribution". When I followed the instruction from the official documentation and tried to use the built-in function "markov_model_local_api", it kept throwing an error. Then I tried to run the sample codes from https://channelattribution.io/pdf/ChannelAttributionWhitePaper.pdf:
from ChannelAttribution import *
#Download data
Data = pd.read_csv("https://channelattribution.io/csv/Data.csv",sep=";")
#Generate token
generate_token(email="my_email", job="my_job", company="my_institution")
token = 'my_token'
#Train
res=markov_model_local_api(token, Data, var_path="path", var_conv="total_conversions",var_value="total_conversion_value", var_null="total_null", order=1, sep=">")
It throws these errors below:
Exception ignored in: <function Connection.__del__ at 0x7fba45595670>
Traceback (most recent call last):
File "/Users/li/opt/anaconda3/lib/python3.8/site-packages/pysftp/__init__.py", line 1013, in __del__
self.close()
File "/Users/li/opt/anaconda3/lib/python3.8/site-packages/pysftp/__init__.py", line 784, in close
if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'
Traceback (most recent call last):
File "src/cypack/ChannelAttribution.pyx", line 1188, in ChannelAttribution.markov_model_local_api
File "src/cypack/ChannelAttribution.pyx", line 894, in ChannelAttribution.__f_initialize_connection
File "/Users/li/opt/anaconda3/lib/python3.8/site-packages/pysftp/__init__.py", line 132, in __init__
self._tconnect['hostkey'] = self._cnopts.get_hostkey(host)
File "/Users/li/opt/anaconda3/lib/python3.8/site-packages/pysftp/__init__.py", line 71, in get_hostkey
raise SSHException("No hostkey for host %s found." % host)
SSHException: No hostkey for host 13.58.174.83 found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/li/Downloads/untitled0.py", line 18, in <module>
res=markov_model_local_api(token, Data, var_path="path", var_conv="total_conversions", var_value="total_conversion_value", var_null="total_null", order=1, sep=">")
File "src/cypack/ChannelAttribution.pyx", line 1248, in ChannelAttribution.markov_model_local_api
UnboundLocalError: local variable 'filename' referenced before assignment
How can I fix all errors and exceptions?
C:\Users\KrunkCiti\AppData\Local\Programs\Python\Python310\Scripts>python OpenGLTensorGrowth.py
Traceback (most recent call last):
File "C:\Users\KrunkCiti\AppData\Local\Programs\Python\Python310\Scripts\OpenGLTensorGrowth.py", line 29, in
Dict = Canvas.winfo_pixels(info, 3840_2160),[Self.tk.getint]
File "C:\Users\KrunkCiti\AppData\Local\Programs\Python\Python310\lib\tkinter_init_.py", line 1163, in winfo_pixels
return self.tk.getint(
AttributeError: 'function' object has no attribute 'tk'
The following is the error code
savePath = "E:\\Desktop\\output\\?.html"
file = open(savePath, 'wb')
After running the error message is as follows:
Traceback (most recent call last): File "Main.py", line 35, in
<module>
crawler.testSaveContent("E:\\Desktop\\output\\?.html") File
"E:\Desktop\MyCrawler.py", line 77, in testSaveContent
file = open(savePath, 'wb') OSError: [Errno 22] Invalid argument:
'E:\\Desktop\\output\\?.html'
my python version is 3.6.3
Traceback (most recent call last):
File "E:\blahblahblah\emailsend.py", line 26, in <module>
msg.attach(MIMEText(file))
File "E:\blahblahblah\Python 2.7.11\lib\email\mime\text.py", line 30, in __init__
self.set_payload(_text, _charset)
File "E:\blahblahblah\Python 2.7.11\lib\email\message.py", line 226, in set_payload
self.set_charset(charset)
File "E:\blahblahblah\Python 2.7.11\lib\email\message.py", line 268, in set_charset
cte(self)
File "E:\blahblahblah\Python 2.7.11\lib\email\encoders.py", line 73, in encode_7or8bit
orig.encode('ascii')
AttributeError: 'file' object has no attribute 'encode'https://stackoverflow.com/questions/ask#
I've been looking this up a lot but I haven't found an answer.
The only important parts of the code is this:
file = open('newfile.txt')
msg.attach(MIMEText(file))
There are other parts but I've debugged it and I get the error at the 'msg.attach(MIMEText(file))' line.
Any help?
MIMEText takes the content of the file, not the file object.
msg.attach(MIMEText(open("newfile.txt").read()))
I am new to python. And I need to run getmail. After lots of error msgs I reduced my claim to run the tests under lib/test first:
python .\test\regrtest.py -v -M 2.0Gb -uall,-bsddb,-largefile
I am getting failure msgs from some of them but at:
test test_re failed -- Traceback (most recent call last):
File "F:\python27_64\lib\test\test_support.py", line 1287, in wrapper
return f(self, maxsize)
File "F:\python27_64\lib\test\test_re.py", line 973, in test_large_search
s = 'a' * size
OverflowError: cannot fit 'long' into an index-sized integer
Warning -- files was modified by test_sax
test test_shutil failed -- Traceback (most recent call last):
File "F:\python27_64\lib\test\test_shutil.py", line 138, in test_rmtree_dont_delete_file
handle, path = tempfile.mkstemp()
File "F:\python27_64\lib\tempfile.py", line 314, in mkstemp
return _mkstemp_inner(dir, prefix, suffix, flags)
File "F:\python27_64\lib\tempfile.py", line 245, in _mkstemp_inner
_set_cloexec(fd)
File "F:\python27_64\lib\tempfile.py", line 50, in _set_cloexec
flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
AttributeError: 'module' object has no attribute 'F_GETFD'
python is hangup :-(
ALL ideas are welcome