I try to set some config attributes with an customm section. Then when I want to read the attributes I get an NoSectionError. The example below is absolute basic and may don't make sense in this way. But I need to read the config in the build method.
Versions used:
Python 2.7
kivy 1.9.1
Example
class MyTestApp(App):
def build(self):
Config.get('user_settings', 'strategy1')
return FloatLayout()
def build_config(self, config):
config.setdefaults('user_settings',
{
'strategy1': 'example',
'strategy2': 'example'
})
MyTestApp().run()
Result in the following exception:
Traceback (most recent call last):
File "test/main.py", line 59, in <module>
MyTestApp().run()
File "C:\Python27\lib\site-packages\kivy\app.py", line 802, in run
root = self.build()
File "test/main.py", line 17, in build
Config.get('user_settings', 'strategy1')
File "C:\Python27\lib\site-packages\kivy\config.py", line 433, in get
value = PythonConfigParser.get(self, section, option, **kwargs)
File "C:\Python27\lib\ConfigParser.py", line 607, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'user_settings'
Inside the app you'll have to use self.config instead of Config
Related
SDK version: 1.0.43
To minimize clicking and compare accuracy between PipelineRuns, I'd like to log a metric from inside a PythonScriptStep to the parent PipelineRun. I thought I could do this like:
from azureml.core import Run
run = Run.get_context()
foo = 0.80
run.parent.log("accuracy",foo)
however I get this error.
Traceback (most recent call last):
File "get_metrics.py", line 62, in <module>
run.parent.log("geo_mean", top3_runs)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/run.py", line 459, in parent
return None if parent_run_id is None else get_run(self.experiment, parent_run_id)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/run.py", line 1713, in get_run
return next(runs)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/run.py", line 297, in _rehydrate_runs
yield factory(experiment, run_dto)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/run.py", line 325, in _from_dto
return PipelineRun(experiment=experiment, run_id=run_dto.run_id)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/run.py", line 74, in __init__
service_endpoint=_service_endpoint)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/_graph_context.py", line 46, in __init__
service_endpoint=service_endpoint)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/_aeva_provider.py", line 118, in create_provider
service_endpoint=service_endpoint)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/_aeva_provider.py", line 133, in create_service_caller
service_endpoint = _AevaWorkflowProvider.get_endpoint_url(workspace, experiment_name)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/pipeline/core/_aeva_provider.py", line 153, in get_endpoint_url
workspace_name=workspace.name, workspace_id=workspace._workspace_id)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/workspace.py", line 749, in _workspace_id
self.get_details()
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/workspace.py", line 594, in get_details
self._subscription_id)
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/_project/_commands.py", line 507, in show_workspace
AzureMachineLearningWorkspaces, subscription_id).workspaces,
File "/azureml-envs/azureml_ffecfef6fbfa1d89f72d5af22e52c081/lib/python3.6/site-packages/azureml/core/authentication.py", line 112, in _get_service_client
all_subscription_list, tenant_id = self._get_all_subscription_ids()
TypeError: 'NoneType' object is not iterable
Update
On further investigation, I tried just printing the parent attribute of the run with the line below and got the same Traceback
print("print run parent attribute", run.parent)
The get_properties() method the below. I'm guessing that azureml just uses the azureml.pipelinerunid property for pipeline tree hierarchy, and that the parent attribute has been left for any user-defined hierarchies.
{
"azureml.runsource": "azureml.StepRun",
"ContentSnapshotId": "45bdecd3-1c43-48da-af5c-c95823c407e0",
"StepType": "PythonScriptStep",
"ComputeTargetType": "AmlCompute",
"azureml.pipelinerunid": "e523d575-c373-46d2-a4bc-1717f5e34ec2",
"_azureml.ComputeTargetType": "batchai",
"AzureML.DerivedImageName": "azureml/azureml_dfd7f4f952ace529f986fe919909c3ec"
}
Please upgrade your SDK to the latest version. Seems like this issue was fixed sometime after 1.0.43.
Was run defined? Can you try ...
run = Run.get_context()
run.parent.log('metric1', 0.80)
I'm unable to repro on 1.0.60 (latest) or 1.0.43 (as in post)
I can do run.parent.log()
run = Run.get_context()
run.parent.log('metric1', 0.80)
in my step
and then I can do
r = Run(ws.experiments["expName"], runid)
r.get_metrics()
and can see metric on pipeline run.
Unclear if i miss something.
I have the following factory:
class ContactFactory(DjangoModelFactory):
name = Faker('company')
industry = Iterator(Industry.objects.all())
class Meta:
model = 'sales.contact'
#post_generation
def requested_devices(self, create, extracted, **kwargs):
if create:
self.requested_devices.add(MSize.objects.first())
And I'm trying to write a test such as:
class TestUserCanAskQuestion(TestCase):
#classmethod
def setUpTestData(cls):
call_command('insert_initial_data')
def setUp(self):
self.contact = ContactFactory()
But everytime I run the test, it results in "StopIteration" error.
Here is the full stack trace:
ERROR: test_dummy (comminquiry.tests.test_views.TestUserCanAskQuestion)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/c/Users/Alire/Projects/mm/mm-bpmui/src/comminquiry/tests/test_views.py", line 32, in test_dummy
a = ContactFactory.build()
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/base.py", line 546, in build
return cls._generate(enums.BUILD_STRATEGY, kwargs)
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/base.py", line 500, in _generate
return step.build()
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/builder.py", line 272, in build
step.resolve(pre)
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/builder.py", line 221, in resolve
self.attributes[field_name] = getattr(self.stub, field_name)
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/builder.py", line 375, in __getattr__
extra=context,
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/declarations.py", line 196, in evaluate
value = next(iter(self.iterator))
File "/mnt/c/Users/Alire/Projects/mm/venv/lib/python3.5/site-packages/factory/utils.py", line 136, in __iter__
value = next(self.iterator)
StopIteration
----------------------------------------------------------------------
Ran 1 test in 2.433s
If I move the ContactFactory() outside of class, the error disappears.
I'm I missing something? or it's a bug in factory boy or django?
(I'm using factory_boy==2.11.1 and django==2.1.2)
As #dirkgroten had suggested, one the fields was returning an empty queryset. This was the root cause of the error.
i'm trying to display a directory tree within a panel in wxpython. I'm using this line of code for the purpose:
self.dir = wx.GenericDirCtrl(rightpanel, -1, dir='C:',
style=wx.DIRCTRL_DIR_ONLY,
size=wx.Size(60, 60))
but i get this huge error message:
Traceback (most recent call last):
File "C:\Python27\3pane.py", line 85, in <module>
app = MyApp(0)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8628, in __init__
self._BootstrapApp()
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8196, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Python27\3pane.py", line 79, in OnInit
frame = MyFrame(None, -1, 'TAA')
File "C:\Python27\3pane.py", line 55, in __init__
size=wx.Size(60, 60))
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_controls.py", line 5663, in __init__
_controls_.GenericDirCtrl_swiginit(self,_controls_.new_GenericDirCtrl(*args, **kwargs))
PyAssertionError: C++ assertion "strcmp(setlocale(LC_ALL, NULL), "C") == 0" failed at ..\..\src\common\intl.cpp(1449) in wxLocale::GetInfo(): You probably called setlocale() directly instead of using wxLocale and now there is a mismatch between C/C++ and Windows locale.
Things are going to break, please only change locale by creating wxLocale objects to avoid this!
i really need help with this.
Thanks.
I am following the code in the readthedocs (http://django-permission.readthedocs.org/en/latest/). Difficulty starts at Apply permission logic section of the docs. All works fine as I cut&paste
art1 = Article.objects.create(
title="Article 1",
body="foobar hogehoge",
author=user1
)
The following traceback is generated
Traceback (most recent call last):
File "<console>", line 4, in <module>
File "C:\Django\test_permissions\lib\site-packages\django\db\models\manager.py", line 157, in create
return self.get_queryset().create(**kwargs)
File "C:\Django\test_permissions\lib\site-packages\django\db\models\query.py", line 320, in create
obj = self.model(**kwargs)
File "C:\Django\test_permissions\lib\site-packages\django\db\models\base.py", line 417, in __init__
raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])
TypeError: 'author' is an invalid keyword argument for this function
If it is changed to
art1 = Project.objects.create(
rest of code is okay
It works okay. So I guess an error. Maybe, I'm unsure.
Anyway, still cut&paste into shell until I get to
>>> assert user1.has_perm('permission.change_article') == False
Traceback (most recent call last):
File "<console>", line 1, in <module>
AssertionError
So I try
>>> assert user1.has_perm('permission.change_article') == True
Works fine. I have to say at this stage I have no idea as to what is going on.
So next line is
assert user1.has_perm('permission.change_article', art1) == True
And now the traceback
>>> assert user1.has_perm('permission.change_article', art1) == True
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\django\test_permissions\lib\site-packages\django\contrib\auth\models.py", line 336, in has_perm return _user_has_perm(self, perm, obj)
File "c:\django\test_permissions\lib\site-packages\django\contrib\auth\models.py", line 273, in _user_has_perm if backend.has_perm(user, perm, obj):
File "c:\django\test_permissions\lib\site-packages\permission\backends.py", line 71, in has_perm if handler.has_perm(user_obj, perm, obj=obj):
File "c:\django\test_permissions\lib\site-packages\permission\handlers.py", line 237, in has_perm if permission_logic.has_perm(user_obj, perm, obj):
File "c:\django\test_permissions\lib\site-packages\permission\logics\author.py", line 122, in has_perm author = field_lookup(obj, self.field_name)
File "c:\django\test_permissions\lib\site-packages\permission\utils\field_lookup.py", line 42, in field_lookup return field_lookup(field_lookup(obj, field_path[0]), field_path[1])
File "c:\django\test_permissions\lib\site-packages\permission\utils\field_lookup.py", line 41, in field_lookup return getattr(obj, field_path[0])
AttributeError: 'Project' object has no attribute 'project'
Have I done something wrong?
I have no idea what to do. I am as far out as Bishops Rock Lighthouse ;-)
I need to get permissions working for my project. Is this the app to go with?
BTW.
(test_permissions) c:\django\test_permissions\test_permissions>pip freeze
Django==1.6.5
Pillow==2.2.2
South==0.8.4
app-version==0.1.2
django-appconf==0.6
django-crispy-forms==1.4.0
django-permission==0.8.0
six==1.7.0
tolerance==0.1.1
Working in virtualenv on Win7
Tommy.
I'm the author of this library.
I'm really sorry but the example code was mis-leading. If you follow the Note section which said "From django-permission version 0.8.0, you can specify related object with field__name attribute like django queryset lookup. See the working example below:", the Article does not have author that's why django blame your code. It should be something like
prj1 = Project.objects.create(
title="Project 1",
body="hello",
author=user1,
)
art1 = Article.objects.create(
title="Article 1",
body="foobar hogehoge",
project=prj1,
)
Then the example should work.
I'll update the document as soon as possible.
I try to create a configuration file, where I can store constants.
Whenever I try with ConfigParser, I get an error
Traceback (most recent call last):
File "/home/baun/google_appengine/google/appengine/ext/webapp /__init__.py", line 511, in __call__
handler.get(*groups)
File "/home/baun/workspace/octopuscloud/s3/S3.py", line 138, in get
test = parser.get('bucket', 'bucketname')
File "/usr/lib/python2.5/ConfigParser.py", line 511, in get
raise NoSectionError(section)
NoSectionError: No section: 'bucket'
simple.cfg:
[bucket]
bucketname: 'octopus_storage'
s3.py:
...
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('simple.cfg')
...
# Get values from the config file
test = parser.get('bucket', 'bucketname')
...
How can I fix this?
===============================
The problem is fixed. The code was correct, but simple.cfg was in the wrong directory.
[bucket]
bucketname= octopus_storage