Trying to setup client Python script in my Windows system and finally i got stuck up with the below error, Tried in the Google and myself of about 4 hrs. But not able find out the solution. Since i am very new to the Python, I could not able to find out the solution.
Please have a look at below code and its error, So you may have solution for me,
Error:
C:\Python26>python C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py
Traceback (most recent call last):
File "C:\xampp\htdocs\cequel-dev\mbtools\main_inject.py", line 12, in <module>
import injectdir
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\__init__.py", line 10, in <module>
import action
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\__init__.py", line 1, in <module>
from command import list
File "C:\xampp\htdocs\cequel-dev\mbtools\injectdir\action\command.py", line 28, in <module>
action_list[action.name]=action
AttributeError: 'module' object has no attribute 'name'
Code: (Line no: 19 to 28)
try:
action_list={}
for file in filenames:
if file.endswith('.py') and file != '__init__.py' and file != 'command.py':
#Import the file as a module action_imp
exec "import {0} as action_imp".format(file[0:-3])
#Get the action object from action_imp. Name is a required method for all actions
action=action_imp
#Put the file name in file_name
action.file_name=file[0:-3]
action_list[action.name]=action
except:
This seems like a array attribute error. So i have tried with if condition, But no luck so far.
So i have stuck with the last line ( "action_list[action.name]=action" ). Please let me know if you have any suggestions or any quick solution to suppress the error in the for loop.
Thanks.
As the comment after the exec statement says, every action has to have a name.
Ensure that every file listed in filenames (except __init__.py and command.py) contains a variable name.
Alternatively, you can suppress the error by replacing line 28 with:
try:
action_list[action.name]=action
except AttributeError:
print "Could not register action", action.file_name
Related
May I ask for some help? I am attempting to clone an existing GitHub project and am struggling to identify what I could be doing wrong. The project is a pluggable SXM music player written in Python ( https://github.com/AngellusMortis/sxm-player), that I've cloned and attempted to run through Visual Studio Code (v1.65.2). Upon executing the project, the code returns an error - "Exception has occurred: AttributeError module 'select' has no attribute 'poll'". Little doubt that I must be doing something incorrectly - but to this point, I haven't been able to identify what I need to do differently to get it to run properly. My sincerest apologies for needing to ask this probably simple question on this forum, but I know that this would be the place to find the experience to get this package up and running and any assistance would be greatly appreciated.
Here is the traceback for the error message:
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 173, in FFmpeg
_stderr_poll: Optional[select.poll] = None
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 169, in <module>
class FFmpeg:
File "C:\GitHub\sxm-player\sxm_player\runner.py", line 9, in <module>
from sxm_player.utils import configure_root_logger
File "C:\GitHub\sxm-player\sxm_player\handlers.py", line 6, in <module>
from sxm_player.runner import Runner, Worker
File "C:\GitHub\sxm-player\sxm_player\cli.py", line 23, in <module>
from sxm_player import handlers
File "C:\GitHub\sxm-player\sxm_player\__main__.py", line 3, in <module>
from sxm_player.cli import main
I need to create a simple script for fixing indentation in python scripts of the repository. I found fix_multiple_files in autopep8 module:
import autopep8
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options={'recursive': 1})
I'm getting this every time I run the script:
Traceback (most recent call last):
File "/home/playrix/work/ci-teamcity/scripts/1.py", line 4, in <module>
autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options='')
File "/home/playrix/.local/lib/python2.7/site-packages/autopep8.py", line 3897, in fix_multiple_files
filenames = find_files(filenames, options.recursive, options.exclude)
AttributeError: 'str' object has no attribute 'recursive'
How correctly noticed johnsharpe it was argparse.Namespace. And the best way to get it was:
opt = autopep8.parse_args(arguments=['recursive', '--in-place', '--aggressive'])
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.
I am trying to do grass scripting in Eclipse and i follow the instructions outlined in this page. I think i have everything configured however when i try to import grass.script i get the following message:
Traceback (most recent call last):
File "/home/nesic/Desktop/grass_dev/Simulacije/test.py", line 6, in <module>
import grass.script as grass
File "/usr/lib/grass64/etc/python/grass/script/__init__.py", line 1, in <module>
from core import *
File "/usr/lib/grass64/etc/python/grass/script/core.py", line 38, in <module>
gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
File "/usr/local/lib/python2.6/posixpath.py", line 67, in join
elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
What am I doing wrong?
os.getenv("GISBASE") most likely returns None, because the envorinment variable GISBASE is not set. That then leads to the AttributeError: 'NoneType' object has no attribute 'endswith' you're seeing.
Try setting GISBASE according to http://grass.osgeo.org/grass70/manuals/variables.html:
GISBASE
directory where GRASS lives. This is set automatically by the startup script.
(BTW, if you don't know about it already, there's also gis.stackexchange.org)
I have a function that decodes an exception and pushes the info to a file. Following is what I do basically:
exc_info = sys.exc_info
txt = cgitb.text(exc_info)
Using this, I got the following exception trace:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\job_queue\utils\start_workers.py", line 40, in start_worker
worker_loop(r_jq, worktype, worker_id)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 55, in worker_loop
_job_machine(*job)
File "C:\Python27\lib\site-packages\job_queue\server\jq_worker.py", line 34, in _job_machine
do_verbose_exception()
File "C:\Python27\lib\site-packages\job_queue\server\errors.py", line 23, in do_verbose_exception
txt = cgitb.text(exc_info)
File "C:\Python27\lib\cgitb.py", line 214, in text
formatvalue=lambda value: '=' + pydoc.text.repr(value))
File "C:\Python27\lib\inspect.py", line 885, in formatargvalues
specs.append(strseq(args[i], convert, join))
File "C:\Python27\lib\inspect.py", line 840, in strseq
return convert(object)
File "C:\Python27\lib\inspect.py", line 882, in convert
return formatarg(name) + formatvalue(locals[name])
KeyError: 'connection'
I ran the code multiple times after this exception, but couldn't reproduce it. However, I didn't find any reference in files cgitb.py or inspect.py to a dict with 'connection' key either.
Will anybody know if this is an issue with python's cgitb or inspect files? Any helpful inputs?
You passed a wrong type to text function
below is the correct way.
cgitb.text((sys.last_type, sys.last_value, sys.last_traceback))
Im not sure specifically why this exception is happening, but have you read the docs for cgitb module? It seems that since python 2.2 it has supported writing exceptions to a file:
http://docs.python.org/library/cgitb.html
Probably something like:
cgitb.enable(0, "/my/log/directory") # or 1 if you want to see it in browser
As far as your actual traceback, are you sure 'connection' isnt a name you are using in your own code? 'inspect' module is most likely trying to examine your own code to build the cgi traceback info and getting a bad key somewhere?