I am getting an error when trying to run a python script in Linux. I am trying to run a Firewall configuration converter I have dowloaded from here:
https://github.com/glennake/DirectFire_Converter
(converter.py file)
First I was getting an error related to logger, but after running a pip3 install logger it has been fixed. Now I am getting NameError: name 'logging' is not defined, despite of code looking good as far I know. For some reason, it looks like this line is not working:
logger = logging.getLogger(__name__)
But I am seeing that all modules are being imported properly. Any idea about what is bringing the issue? Thanks.
full error traceback:
Traceback (most recent call last):
File "converter1.py", line 257, in <module>
main(src_format=args.source, dst_format=args.destination, routing_info=args.routing)
File "/home/ubuntu/.local/lib/python3.8/site-packages/traceback_with_variables/print.py", line 98, in wrapper
return func(*args, **kwargs)
File "converter1.py", line 233, in main
parsed_data = parse(
File "converter1.py", line 107, in parse
from DirectFire.Converter.parsers.ciscoasa_pre83 import parse
File "/home/ubuntu/DirectFire_Converter/DirectFire/Converter/parsers/ciscoasa_pre83.py", line 23, in <module>
logger = logging.getLogger(__name__)
NameError: name 'logging' is not defined
You need to import, add import logging at the top of your file
Related
I have a Python Code to conduct an experiment. To ensure that the Code is working smoothly I wanted to run a trial round via 'otree devserver', but I always get an AttributeError message and I am stuck here. Can anyone help me out?
I have downloaded the Code from GitHub and downloaded all required packages. I am using macOS, otree-5.10.2 and django-4.1.7. Here is my full traceback / error message:
Traceback (most recent call last): File
"/Users/.otreevenv/bin/otree", line 8, in
sys.exit(execute_from_command_line()) File "/Users/.otreevenv/lib/python3.10/site-packages/otree/main.py", line
108, in execute_from_command_line
setup() File "/Users/.otreevenv/lib/python3.10/site-packages/otree/main.py", line
132, in setup
from otree import settings File "/Users/.otreevenv/lib/python3.10/site-packages/otree/settings.py",
line 50, in
OTREE_APPS = get_OTREE_APPS(settings.SESSION_CONFIGS) File "/Users/.otreevenv/lib/python3.10/site-packages/django/conf/__init__.py",
line 94, in __getattr__
val = getattr(_wrapped, name) File "/Users/.otreevenv/lib/python3.10/site-packages/django/conf/__init__.py",
line 270, in __getattr__
return getattr(self.default_settings, name) AttributeError: module 'django.conf.global_settings' has no attribute 'SESSION_CONFIGS'. Did
you mean: 'SESSION_ENGINE'?
I'm having trouble debugging unit tests in pycharm. I can run them fine with my configuration but when I run the debugger I get the following error output:
Error
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 34, in testFailure
raise self._exception
ImportError: Failed to import test module: tests
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/Users/paymahn/solvvy/scheduler/tests/__init__.py", line 2, in
import tests.test_setup_script
File "/Users/paymahn/solvvy/scheduler/tests/test_setup_script.py", line 3, in
import setup
File "/Applications/PyCharm.app/Contents/helpers/pydev/setup.py", line 87, in
data_files.append(('pydevd_attach_to_process', [os.path.join('pydevd_attach_to_process', f) for f in os.listdir('pydevd_attach_to_process') if accept_file(f)]))
FileNotFoundError: [Errno 2] No such file or directory: 'pydevd_attach_to_process'
My directory structure is:
My unittest configuration is:
tests/test_setup_script.py looks like:
import unittest
import os
import setup # the path to this file is scheduler/setup.py. This import may be breaking things
class TestSetupScript(unittest.TestCase):
def test_load_db_connection_valid_yaml_file(self):
file_name = "valid-yaml.yml"
with open(file_name, 'w') as file:
file.write("""
test:
hello world
a = b
""")
yaml = setup.load_yaml_configuration(file_name)
# I want to debug the line above, hence no assertions here
What does pydevd_attach_to_process do and how can I make sure it's found during debugging? Is the problem not actually related to that file/directory being found?
Indeed, the failure occurs because the "import setup" in your code imports the setup module which is part of PyCharm's debugger runtime instead of your own setup module. The easiest fix to this is to rename your setup.py file to something else and to update the imports in your code accordingly.
I'm learning to use tqdm. I made a very simple test case but met with NameError. The test case is as follows:
from tqdm import tqdm_notebook
num = 100
bar = tqdm_notebook(total=num)
The file name is b.py and I run:
python b.py
The error happened and the error message is:
Traceback (most recent call last):
File "b.py", line 4, in <module>
bar = tqdm_notebook(total=num)
File "/usr/local/lib/python2.7/dist-packages/tqdm/__init__.py", line 19, in tqdm_notebook
return _tqdm_notebook(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tqdm/_tqdm_notebook.py", line 183, in __init__
self.sp = self.status_printer(self.fp, self.total, self.desc)
File "/usr/local/lib/python2.7/dist-packages/tqdm/_tqdm_notebook.py", line 104, in status_printer
ptext = HTML()
NameError: global name 'HTML' is not defined
I thought it was because I did not install a package named HTML, so that I run
sudo pip install HTML
It did installed an HTML package. But the error remained the same when I run the test case again.
What's wrong with this example? Did I miss other packages? Thank you all for helping me!
I am trying to import theano in a module, but I am getting a traceback:
File "/media/tarun/6A86CA8286CA4DEF/develop/pydy/pydy/codegen/code.py", line 16, in <module>
import theano
File "/usr/local/lib/python2.7/dist-packages/theano/__init__.py", line 44, in <module>
from theano.gof import \
File "/usr/local/lib/python2.7/dist-packages/theano/gof/__init__.py", line 38, in <module>
from theano.gof.cc import \
File "/usr/local/lib/python2.7/dist-packages/theano/gof/cc.py", line 55, in <module>
StrParam(""))
File "/usr/local/lib/python2.7/dist-packages/theano/configparser.py", line 223, in AddConfigVar
root=newroot, in_c_key=in_c_key)
File "/usr/local/lib/python2.7/dist-packages/theano/configparser.py", line 227, in AddConfigVar
configparam.fullname)
AttributeError: ('This name is already taken', 'gcc.cxxflags')
It seems that there is some name conflict in some config. Can anybody please point me to the same.
This error happens because some module, probably theano.gof, is imported twice. Usually, this is because a first call to import theano.gof gets started, registering 'gcc.cxxflags' in the configuration parser a first time, but then raises ImportError, which is catched and ignored.
Then, import theano.gof gets called again, tries to register the option again, which raises the exception you get.
Is there any traceback or error message before this one, or something that would give a hint of why the first import failed?
I got similar error using when using the jupyter notebook. Restarting kernel solved the issue.
I'm testing ebaysdk Python library that lets you connect to ebay. Now I'm trying examples from: https://github.com/timotheus/ebaysdk-python/
So far I got stuck at this example:
from ebaysdk.shopping import Connection as Shopping
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file="ebay.yaml")
response = shopping.execute('FindPopularItems',
{'QueryKeywords': 'Python'})
print response.disct()
When I run it. It gives me this error:
Traceback (most recent call last):
File "ebay-test.py", line 13, in <module>
{'QueryKeywords': 'Python'})
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 123, in execute
self.error_check()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 193, in error_check
estr = self.error()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/connection.py", line 305, in error
error_array.extend(self._get_resp_body_errors())
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/shopping/__init__.py", line 188, in _get_resp_body_errors
dom = self.response.dom()
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 229, in dom
return self._dom
File "/usr/local/lib/python2.7/dist-packages/ebaysdk-2.1.0-py2.7.egg/ebaysdk/response.py", line 216, in __getattr__
return getattr(self._obj, name)
AttributeError: 'Response' object has no attribute '_dom'
Am I missing something here or it could be some kind of bug in library?
Do you have a config file? I had a lot of problems getting started with this SDK. To get the yaml config file to work, I had to specify the directory that it was in. So in your example, it would be:
shopping = Shopping(domain="svcs.sandbox.ebay.com", config_file=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ebay.yaml'))
You should also be able to specify debug=true in your Shopping() declaration as in Shopping(debug=True).
Make sure if you have not, to specify your APP_ID and other necessary values in the config file.
You have the wrong domain, it should be open.api.sandbox.ebay.com. See this page on the ebaysdk github.